

This is where you will want to use Debug.Assert. This may be cumbersome when you have loop running and are not sure when the error will occur or if you are aware of a condition that causes the error but are unable to catch it at the right moment. Often breakpoints are specified in places where error might occur. Assertions – the right way to breakpoint errors Click on the dot again to remove the breakpoint. A red dot should appear indicating that you have specified a new breakpoint. To add/remove a breakpoint simply left-click on the left gray bar in your VBA Project View next to your code.

They are convenient when you want to be sure your code does run through a certain loop of If statement. Break pointsīreakpoints specify lines of code at which the execution of your macro should pause when you debug VBA. These are the basic commands for running macros. You can also stop a running macro by hitting the Esc button

You should find 3 buttons as shown below: Let’s start with the tool bar at the top of the VBA Project Viewer window. Breakpoint – a line of code at which the execution of the macro will pause.Debugging code– the process of finding and fixing bugs/defects.Executing/Running code – the process of running a macro.Debug VBA: Basic termsįirst we need to introduce some basic terms to facilitate the remaining part of this post: This makes life much easier and debugging some much more pleasant! So let’s jump right to it.

Basically find that bug and kill it! Excel VBA compared to other programming languages / environments has one significant advantage – you can debug code on the fly without having to recompile the code. I was amazed that most of them preferred to keep at it, trying to pin down the one line of code the causes their issues, rather then spend a few minutes learning how to properly debug Excel code and get the job done much faster! Introducing today’s post on how to debug VBA code!ĭebugging is essentially a methodical process of locating and fixing bugs (or defects as some prefer). Writing Visual Basic for Applications code is hard, but what about writing VBA code that works and to write it fast? Often I found many colleges struggling to get a few simple procedures to work.
