About this lesson
How to trigger various errors in VBA, and what they mean.
Download this lesson’s exercise file.Error types.xlsm
Dealing with error messages
When to use
To help debug code when an error message appears
- The "On Error Resume Next" command suppresses errors from the user interface
- While On Error Resume Next is active, the macro will continue to run through the code despite any errors being triggered
Resuming Regular Error Handling
- The "On Error GoTo 0" statement resumes normal error handling
- The macro will once again go into break mode when it encounters an error and gives you the option to end or debug the code
Hints & tips
- While activating On Error Resume Next to just ignore errors may seem like a good idea, it is a dangerous habit
- On Error Resume Next should be activated when you expect an error and want to "trap" it for later inspection
- Once the error has been tested, you should resume normal error handling again
Lesson notes are only available for subscribers.