MS Excel 2007: Using the Immediate Window
This Excel tutorial explains how to use the Immediate Window in the VBA debugging environment in Excel 2007 (with screenshots and step-by-step instructions).
See solution in other versions of Excel:
Using the Immediate Window
In Excel 2007, the Immediate window can be used to debug your program by allowing you to enter and run VBA code in the context of the suspended program.
We've found the Immediate window to be the most help when we need to find out the value of a variable, expression, or object at a certain point in the program. This can be done using the print command.
For example, if you wanted to check the current value of the variable called pValue, you could use the print command as follows:
In this example, we typed print pValue in the Immediate window and pressed ENTER.
print pValue
The Immediate window displayed the result in the next line. In this case, the print pValue command returned 56.79.
You can also type more complicated expressions in the Immediate window. (Remember to press ENTER.) For example:
In this example, we typed print Int(pValue) in the Immediate window and pressed ENTER.
print Int(pValue)
The Immediate window displayed the result of 56 in the next line.
The Immediate window can be used to run other kinds of VBA code, but bear in mind that the Immediate window can only be used when debugging so any code that you run is for debugging purposes only. The code entered in the Immediate window does not get saved and added to your existing VBA code.
Advertisements