0% found this document useful (0 votes)
44 views3 pages

Common Error Messages in VBA and What They Mean

This document discusses common errors that occur in VBA coding and how to resolve them. It provides explanations for common error messages and problems encountered in lectures 7 and 8 on VBA macros. Some examples of errors covered include syntax errors, incorrect number of arguments, missing punctuation, and bugs. Troubleshooting tips are provided such as checking for missing "End If" statements, verifying macro names, and fixing logic in conditional statements.

Uploaded by

Mavis C
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views3 pages

Common Error Messages in VBA and What They Mean

This document discusses common errors that occur in VBA coding and how to resolve them. It provides explanations for common error messages and problems encountered in lectures 7 and 8 on VBA macros. Some examples of errors covered include syntax errors, incorrect number of arguments, missing punctuation, and bugs. Troubleshooting tips are provided such as checking for missing "End If" statements, verifying macro names, and fixing logic in conditional statements.

Uploaded by

Mavis C
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Common Errors in VBA and What They Mean

And How to Resolve Common Problems


Mr. Jonathan Y. H. Sim ([email protected])
Instructor, Department of Philosophy

Errors & Problems Common to Lecture 7

Error Message: Cannot run the macro <name of macro>. The macro may not be available in
this workbook or all macros may be disabled.

Either you didn’t enable macros when you opened the file, OR, you renamed one of
the sub-routines but forgot to reassign the button to the newly named sub-routine.

If you renamed the sub-routine, you will need to reassign the button. To do so, right
click the button, click “Assign macro” and then select the name of the new sub-
routine, and click ok.

Error Message: Syntax error

There is a typo. Usually it’s a missing punctuation, or wrong punctuation used.

Error Message: Method 'Range' of object '_Global' failed

This usually happens when you made a typo in one of the functions that require the
use of brackets. E.g. Range("A1").Select needs to have the quotation marks, but you
forgot the quotation marks.

Error Message: Wrong number of arguments or invalid property assignment

This happens when you have too many inputs for functions requiring the use of
brackets. E.g. Cells(1,1).Value requires you to put two inputs (row number and
column number), but you might have typed something like Cells(1,2,3).Value

Error Message: Expected: expression

You wrote an extra comma somewhere inside the brackets of a function, but you
didn’t provide the input that’s expected after the comma. E.g. Cells(1,1,).Value
Error Message: Object doesn't support this property or method

This usually happens when you misspell VBA commands. E.g.


Selection.Interior.Colour (wrong) instead of Selection.Interior.Color (correct). Or
Cells(1,1).Vlaue (wrong) instead of Cells(1,1).Value

Error Message: Compile Error: Expected Then or GoTo

Your IF condition is missing the word “Then”

Error Message: Else without If

You have an Else but a missing If. This usually happens when you premature type
End If before the Else.

Error Message: Block If without End If

You have an If but you are missing the End If. Remember: Every If needs an End If.

Error Message: Runtime Error 502960

This is a Microsoft bug. Save your work and close Excel completely and reopen
Excel. The problem will go away.

Problem: You used a colour other than black, yellow, or red, and the code doesn’t work as
expected. E.g. The character just walks into the coloured square and nothing else happens.

Colours like vbGreen and vbBlue are a specific shade. So you cannot just use any
green or blue. Refer to List of VB Colors.xlsm for the list of VBA colours (Luminus
> Files > Lecture Resources > Lecture 7 and see how you can generate that specific
shade to copy and paste into your maze.

(Common errors for Lecture 8 can be found on the next page…)


Errors & Problems Common to Lecture 8

Error Message: Loop without Do

This usually happens when you have an If conditional that does not have an End If.
It’s important to scan your code to see that every If has a corresponding End If (Elseif
doesn’t need an End If because it’s part of the If block).

Error Message: Do without Loop

You forgot to end your Do While or Do Until block of code with the Loop command.
Find the spot where your loop is supposed to end, and put the word Loop there.

Problem: Excel hangs when trying to do the Maze Challenge (Lecture 8-3 Activity 1).

The most common reason is that there is a problem with the logic of the If
conditionals. For starters, in Lecture 8, the advise was to NEST a set of conditionals
into the Else. Most students write their code like this: IF… IF… IF… IF… This is not
the same as IF… ELSEIF… ELSEIF… ELSEIF…

What’s the difference? If you recall Lecture 4, if you have an IF after the IF, you will
just run them one after the other (the wombat, panda, soybean quiz question). So IF…
IF… IF… IF… can lead to results where more than one of these IFs are activated at
once (thus multiple outcomes). That’s ok if you had intended it (but that’s not what
you want for the maze). Whereas IF… ELSEIF… ELSEIF… will lead to only one
condition being activated (only one outcome).

Problem: Nothing happens when I press F8/Fn-F8 or Cmd-Shift-i

For Windows, the reason why this happens is because your keyboard was configured
to map F8/Fn-F8 to some other purpose like playing a video or changing the output
display options. The easiest workaround is to follow the instructions in this video:
https://youtu.be/ofC8F4fDaDQ

I don’t know why it sometimes doesn’t work for macOS.

You might also like