Keeping track of Excel VBA Variable values when debugging code

We’ve written a post on the VBA Intermediate Window and explained how it can be used to question the value of a VBA variable.

There is another way to show active variables and their values (if they have one) along with the variable’s data type etc.

Load the Locals Window from the View menu…

locals1

When displayed, the window will be blank until you are running through code…

locals2

Start stepping through and you will see that the variable var1 that I defined is now listed in the Locals window. The value is zero because I stopped before the value was assigned…

locals3

Once the variable has been assigned a value the value is displayed in the value column of the Locals window…

locals4

And that is it. Whatever point you are in you macro’s code you can load up the locals window and see exactly what is happening with all your variables. Very helpful when debugging code and if you have lots of variables being used.

No ratings yet.

Please rate this