MS Excel 2003: Add a Watch Expression in VBA
This Excel tutorial explains how to add a Watch expression in the VBA debugging environment in Excel 2003 (with screenshots and step-by-step instructions).
See solution in other versions of Excel:
Adding a Watch Expression
In Excel 2003, the Watch Window displays the value of a watched expression in its current state. This can be extremely useful when debugging VBA code. Let's explore how to add an expression to the Watch Window.
To add a Watch expression, select Add Watch under the Debug menu.
When the Add Watch window appears, enter the expression to watch and click the OK button when you are done.
In this example, we've entered the following watch expression in the Expression field:
LMid(pValue, LPos, 1)
Next, we've selected AlphaNumeric as the Procedure and Module1 as the Module when setting up the Context for the watched expression.
Finally, we've selected Watch Expression as the Watch Type but there are 3 options to choose from:
Watch Type | Description |
---|---|
Watch Expression | To display the value of the watched expression in its current state |
Break When Value Is True | To stop the execution of the code when the value of the watched expression is True |
Break When Value Changes | To stop the execution of the code when the value of the watched expression changes |
Now when you return to the VBA window, the Watch Window will automatically appear if it was previously hidden. Within the Watch Window, all of the watched expressions should be listed including the one that we just added.
As you can see, the expression Mid(pValue, LPos, 1)
now appears in the Watch Window with a value of "1". Adding a watch is a great way to keep track of variables or expressions of interest when debugging your VBA code.
Advertisements