totn Excel 2013 VBA Debugging

MS Excel 2013: Using the Immediate Window

This Excel tutorial explains how to use the Immediate Window in the VBA debugging environment in Excel 2013 (with screenshots and step-by-step instructions).

Using the Immediate Window

In Excel 2013, 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.

Microsoft Excel

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:

Microsoft Excel

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 123 Main St.

You can also type more complicated expressions in the Immediate window. (Remember to press ENTER.) For example:

Microsoft Excel

In this example, we typed print Mid(pValue, LPos, 1) in the Immediate window and pressed ENTER.

print Mid(pValue, LPos, 1)

The Immediate window displayed the result of 1 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.