Tuesday, September 25, 2012

Excel VBA - Macro Errors


Unfortunately, not everything goes right the first time. Excel VBA will sometimes give you a macro error saying that something isn't programmed correctly. There are too many Excel Visual Basic errors to explain them all at this stage. However, here is a good tip to deal with errors.

First, we want to create a macro error.
1. Place a command button on your worksheet and add the following incorrect code line:
MgBox "This is fun"

(instead of the correct line MsgBox "This is fun")
Create a Macro Error

2. Click the command button on the sheet.

Result:
Compile error

3. Click on OK.
4. Next, in the Visual Basic Editor, click on Reset to stop the debugger! (More about the debugger in the next chapter) Now change the code. Excel VBA has colored the word MgBox blue to indicate the macro error.

Stop the Debugger

No comments:

Post a Comment