This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel.
Part 1 of this series discussed basic error handling code using VBA.
Part 2 went in depth on how the VBA to copy values to blank cells works, and how to loop.
Although helpful, it is not necessary to watch parts 1 and 2 before this lesson.
This lesson runs code to see what it does and then breaks working code so we can explore errors. We run and fix, debug, compile, use and not use Option Explicit, step through code while it is running, look at the watch window to see values of variables, set and clear breakpoints, stop, continue running, and learn how debugging and error handling work.
01. For a list of macros, press Alt-F8
When you are in an Excel Workbook, press Alt-F8 for a list of Macros.
02. To go to VBA, press Alt-F11
When you are in an Excel Workbook, press Alt-F11 to go to the Visual Basic Editor (VBE) where you can write Visual Basic for Applications (VBA).
03. To watch variable values, press Ctrl-W
When you are in VBA code, press Ctrl-W to open the Watch window and set expressions to watch the value of. If a variable name is highlighted when Ctrl-W is pressed, it will be filled in the Expression.
Add a Stop statement to the code to cause the code to stop on that line when it runs.
05. To single-step, press F8