Hello Excellers, today let’s look at breaking up our VBA code by setting breakpoints in the actual code. This pauses the code at a point we choose to enable us to use the debugging environment, to perform checks to ensure all is running as expected with our Macro.
First Things First – What Is A Breakpoint?
A breakpoint is a selected line of code that once it has been reached, your macro will be suspended. At this point you use the debugging environment to step through each line of code, halt the code’s execution or view the status of your program. It is a great way to step though and debug your code without having to restart your code from the very beginning each time you want to debug.
There is no limit to how many breakpoints you have in your code
How To Add Break Points To Your VBA Code.
Let’s get down to adding breakpoints into our VBA code. First you will need to open the VBA environment by either hitting the Excel keyboard shortcut ALT+F11 or hit the Developer Tab and then select Visual Basic.
To set a breakpoint in your VBA Code, find the line you want to add to break to.
- Left-click in the grey bar to the left of the code.
- A red dot should appear and the line of code should be highlighted in red.
- Your breakpoint will be inserted.
How To Remove Break Points From Your VBA Code.
Once you have finished debugging your VBA code it is really easy to remove the breakpoints you have inserted.
- Left click on the breakpoint you want to remove
- Your breakpoint will automatically be removed
How To Clear Multiple Break Points From Your Excel VBA Code.
If you have a lot of breakpoints in your VBA code as there is no restriction on how many you can use, then it maybe a challenge to individually go through your code and remove them one by one. If you want to remove all of the breakpoints at once then you can use the debugging menu options.
- Select the Debug Menu
- Select Clear All Breakpoints
- Or use the keyboard shortcut CTRL+SHIFT+F9
If you want to see all of my blog posts in the Macro Mondays Series you can find them all in the link below. Why not book mark it?, Yes it is updated EVERY Monday.