Got any Excel/VBA Questions? Excel Help
No matter how good we become at writing VBA code, debugging is a fact of writing code. Even when our macros return no Runtime errors, we should TRY and force potential code errors.
BREAKPOINT
A selected program line at which execution automatically stops.
To add a breakpoint click the right grey margin within the Procedure at the point the execution should stop.
DEBUG RUNTIME ERRORS
Example of a Runtime Error that requires debugging
To quickly debug macros place your mouse insertion point anywhere in the Procedure and step-through using F8. Each line will be highlighted yellow as you step through. You can make changes and then drag the yellow highlight up/down to repeat/omit lines.
After hitting debug the offending line is highlighted yellow
You can hover your mouse pointer over variables, range objects etc and see their values.
Hover over Range Object and we can see A1 is text NOT a date
Drag the yellow debug highlight up and fix code, then run again
Adding If IsDate to check cell data type fixes degbug error
Also see Immediate Window, Watch Window or Locals Window in the VBA help.
Microsoft and Microsoft Excel are registered trademarks of Microsoft Corporation. OzGrid is in no way associated with Microsoft
See also:
Auto-Run-Macros |
Excel AutoFilters in VBA using Dates |
Criteria for VBA filters |
Excel VBA AutoFilters |
Free Training Course: Lesson 1 - Excel Fundamentals
See also: Index to Excel VBA Code; Index to Excel Freebies; Lesson 1 - Excel Fundamentals; Index to how to… providing a range of solutions
Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.