Find the Yellow Highlighted Line When Debugging in VBA
Did you ever lose your place while debugging in VBA? Here's an easy way to find it.
![Find the Yellow Highlighted Line When Debugging in VBA](/content/images/size/w2000/2022/03/road-5089188_1920.jpg)
One of my favorite features in VBA is the so-called "Edit and Continue."
That's the feature that allows you to set a breakpoint in code, then step through the code one line at a time. The next line of code to be executed is highlighted in yellow. While the program is in break mode, you can wander around the rest of the codebase.
I often wander so far that I forget what line I was troubleshooting in the first place.
When I first started debugging VBA, I would just press F8 to execute the next line of code. That would bring the focus back to wherever I left off. Blindly executing a line of code while debugging is not ideal, though.
Luckily, there is a better way to find that yellow highlighted line of code.
Show Next Statement
At the bottom of the Debug menu, there is a command named "Show Next Statement."
![](https://nolongerset.com/content/images/2022/03/image-16.png)
When you click on that command, the VBIDE window will shift focus to the yellow-highlighted line of code, which is the next statement that will be executed when you press [F8] to "Step Into."
Shortcut Key - [Alt] + [D], [X]
As an alternative to the menu, you can use the shortcut [Alt] + [D], [X] (Debug > Show Next Statement).
Customizing the Debug Toolbar
I can never remember the shortcut key, so I like to have the command one click away by adding it to the Debug Toolbar. Here are the steps:
- View > Toolbars > Customize ([Alt] + [V], [T], [C])
- _| Toolbars |_ > [√] Debug
- _| Commands |_ > Categories: Debug > Commands: Show Next Statement
- Click and drag "Show Next Statement" from the Customize dialog and drop it on the Debug toolbar
You can drop it anywhere you want on the toolbar, but I like to put it between the Break and Reset icons:
![](https://nolongerset.com/content/images/2022/03/image-17.png)
Only Available While Debugging
Be aware that if you are not in break mode, the command does not do anything, and so it will appear grayed out on the toolbar.
![](https://nolongerset.com/content/images/2022/03/image-18.png)
Show Next Statement in Action
Here's a short video clip showing the feature in action:
Image by Joshua Woroniecki from Pixabay