Common Error Messages in VBA and What They Mean
Common Error Messages in VBA and What They Mean
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.
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.
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
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
You have an Else but a missing If. This usually happens when you premature type
End If before the Else.
You have an If but you are missing the End If. Remember: Every If needs an End If.
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.
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).
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).
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