In the VBA Code Editor, we explored the Visual Basic for Applications (VBA) programming environment. In this tutorial, we will take a closer look at one of its key tools — the Immediate Window. This handy feature lets you run VBA statements instantly, test commands, and debug your VBA projects in Excel, Access, and other Microsoft Office applications.
Tip: If the Immediate Window is not visible, press
Ctrl + Gor go to View → Immediate Window from the VBE menu.
The Immediate Window is used for debugging, evaluating expressions, executing statements, and inspecting or changing variable values. Think of it as a live console that allows you to test code snippets without running the entire macro.
Practical Uses of the Immediate Window
1. Running Commands Directly
You can execute any single line of VBA code directly within the Immediate Window. Simply type the statement and press Enter to run it instantly.
- Open the Immediate Window.
- Type a VBA command or statement.
- Press Enter to execute it immediately.
Example:
Type the following code in the Immediate Window:
topic = "VBA"
Then run the next line to display the message box:
MsgBox topic & " makes Office come alive."

Tip: This technique is great for testing short snippets of code or verifying how a particular statement behaves.
2. Viewing and Changing Variable Values
A. Viewing Variable Values
To view the current value of a variable, type a question mark (?) before the variable name:
? myVariable
If the variable has not been initialised, the result will be blank.
B. Changing Variable Values
To modify a variable’s value, use the assignment operator (=):
num = 12
Press Enter, and the value of num will be updated immediately.
3. Calling Subs and Functions
You can also call existing procedures from the Immediate Window. Simply type the module name followed by a dot (.) to activate the IntelliSense list of members.
Tip:
Using the module name before calling a procedure helps you benefit from the IntelliSense feature in the VBE editor. However, public procedures can also be called without specifying the module name.
Once you select or type the procedure name and press Enter, the Sub or Function will execute immediately.
test.MsgMe


4. Displaying Debug Output and Function Results
Another common use of the Immediate Window is to display debugging output. You can insert the Debug.Print statement in your VBA code to send variable values or expressions to the Immediate Window.
Debug.Print variable
To view the return value of a function, simply prefix the function call with a question mark:
? test.iAmTest(10, 20)

In the example above, VBA prints both argument values using Debug.Print and then shows the returned function result.
Summary and Practical Tips
The Immediate Window is one of the most valuable debugging tools in VBA. It allows you to test and analyse code without running the entire project, helping you save time and improve accuracy during development.
- ✅ Run commands instantly by pressing Enter
- 🔍 Inspect variable values using
? - ✏️ Modify variable values at runtime
- ⚙️ Call Subs and Functions via module names
- 🧠 Print debug results using
Debug.Print
Frequently Asked Questions about the Immediate Window in VBA
What is the Immediate Window in VBA used for?
The Immediate Window is a feature within the Visual Basic Editor (VBE) that lets you execute commands, check variable values, and view debugging output. It’s an essential tool for testing code and troubleshooting VBA macros efficiently.
How can I open the Immediate Window in the VBE?
Press Ctrl + G or choose View → Immediate Window from the menu. The window usually appears at the bottom of the Visual Basic Editor.
What’s the difference between Debug.Print and ? in the Immediate Window?
Both are used to display output in the Immediate Window. Debug.Print is used inside procedures to print values during code execution, whereas ? is used directly in the Immediate Window to quickly check variable or expression values.
Can I change variable values from the Immediate Window?
Yes, you can assign new values to variables using simple statements like num = 12. This is especially useful during break mode when testing the impact of different values.
Can I run Subs and Functions directly from the Immediate Window?
Absolutely. As long as the procedure is declared as Public, you can call it directly by name. To use IntelliSense, type the module name first (e.g. Module1.MySub), though this step is optional.
What’s the difference between the Immediate Window and the Watch Window?
The Immediate Window allows you to execute commands and view or modify variables. The Watch Window, on the other hand, automatically tracks and displays variable values during code execution but cannot run commands.
Read More
VBA Built-in Functions | Complete List of Functions in Visual Basic
VBA Procedures | Definition, Types & Usage in Visual Basic
Constants in VBA | Types, Scope, and How to Use Them Effectively
Variable Scope in VBA | How to Access Variables across Different Parts of a Project
VBA Modules | Types of Modules and the Difference Between a Module and a Class
Operator Precedence in VBA | Order of Arithmetic and Logical Operations with Examples
VBA Operators | Performing Data Operations and Building Expressions