keepcalculator

06 Numbers and Powers

VBA Immediate Window: What It Is & How to Use It

Card No. 06·8543 · Updated · Standard formula, shown below

Average pace 5.00 min/km
Average speed
12.00 km/h
Result
Finish time
50 min
You entered
Distance
10 km
You entered
You enter
Finish time, Distance
You get
Average pace, Average speed
Rounding
2 dp

The VBA Immediate Window is a debugging and testing pane in the Visual Basic Editor (VBE) where you can type or paste lines of VBA code and run them instantly, without adding them to a macro. You open it with Ctrl+G in the VBE, and it accepts both direct statements (like ? 2+2) and commands that call existing macros or set variable values. It is one of the fastest ways to inspect values, test expressions, and troubleshoot code while writing or editing macros.

What the Immediate Window Is For

The Immediate Window is part of the Visual Basic Editor, which is the coding environment built into Microsoft Office applications (Excel, Word, Access, PowerPoint, and Outlook). It is not a standalone tool; it lives inside the VBE and is always available while you are writing or running VBA code. Its main job is to give you a scratchpad where you can execute code on the spot, without creating a subroutine or function first.

You can use it for three broad purposes:

  • Quick calculations – type ? 15 * 3 and press Enter to see the result (45) printed on the next line.
  • Testing expressions – check what a function returns, e.g. ? Left("Hello", 2) prints He.
  • Debugging while paused – when your macro hits a breakpoint, you can type ? variableName to see the current value, or even assign a new value to a variable.

It is also a common place to run one-liners that modify objects, like ActiveSheet.Range("A1").Value = 42, which instantly writes 42 to cell A1 on the active worksheet.

How to Open and Close the Immediate Window

There are two standard ways to open the Immediate Window in the VBE:

  1. Press Ctrl+G on your keyboard.
  2. Go to the menu bar: View → Immediate Window (in older versions it is under View or Insert).

If the window is not visible, it may be hidden behind other panes. You can also close it with the X button, but it will reappear next time you press Ctrl+G. The Immediate Window is dockable – you can drag it to the bottom or side of the VBE, or float it separately.

What You Can Type in It

The Immediate Window accepts two kinds of input: statements and expressions. A statement is a line of code that performs an action, such as Range("A1").ClearContents. An expression is a value-producing piece of code; to see its result, you prefix it with a question mark (?) or the word Print.

For example:

  • ? 10 / 4 → prints 2.5
  • Print Now → prints the current date and time
  • ? Application.WorksheetFunction.Max(Range("A1:A10")) → prints the maximum value in that range
  • Debug.Print "Hello" → prints Hello (the Debug object refers to the Immediate Window)

You can also declare variables and assign values, but they only exist while the line is running; they do not persist between lines. For example, typing x = 5 then ? x on the next line will print 5, but if you close the window or run another macro, that variable is gone.

Using It for Debugging

The most powerful use of the Immediate Window is during a paused macro. When you set a breakpoint (click in the gray margin next to a line of code) and run your macro, execution stops at that line. At that moment, you can:

  • Type ? myVariable to see the current value of any variable in scope.
  • Type myVariable = 10 to force a new value, then continue running to test how the macro behaves.
  • Call other procedures, e.g. Call MySub or just MySub.

This is far faster than adding temporary MsgBox lines or writing extra debug code. You can also use the Debug.Print statement inside your macro to send values to the Immediate Window while the macro runs – a common technique for logging progress without interrupting execution.

Common Mistakes and Misconceptions

One common mistake is trying to run multi-line code in the Immediate Window. It only executes one line at a time. If you need to test a loop or a block of code, you must either write it in a module or use the colon (:) to separate statements on a single line, though that is limited.

Another misconception is that the Immediate Window is the same as the “Watch Window� or “Locals Window.� Those are separate debugging panes: the Locals Window shows all variables in the current procedure, and the Watch Window lets you monitor specific expressions. The Immediate Window is for direct interaction, not for continuous monitoring.

Also, note that the Immediate Window does not automatically clear between runs. Old output stays until you clear it, which you can do by selecting all and pressing Delete, or by using Application.SendKeys "^a {DEL}" (though that is unreliable). You can also close and reopen the window to clear it.

Practical Examples

Here are a few things you can try right now to get comfortable:

  • ? 2^10 → prints 1024 (exponentiation)
  • ? Len("Hello") → prints 5
  • ? ActiveSheet.Name → prints the name of the active worksheet
  • ? Range("A1").Value → prints the value in cell A1 of the active sheet
  • Range("B1:B10").Value = 1 → fills B1:B10 with the number 1 (this is a statement, no question mark)

You can also call built-in VBA functions, like ? Format(Now, "yyyy-mm-dd") to see a formatted date, or ? VBA.Strings.StrConv("abc", vbUpperCase) to get “ABC�.

Alternatives to the Immediate Window

If you need to log many values over time, the Immediate Window can become cluttered. Alternatives include:

  • Debug.Print – still sends to the Immediate Window, but you can add labels and formatting.
  • Locals Window – shows all variables in the current procedure automatically.
  • Watch Window – lets you set expressions to monitor and see their values change as you step through code.
  • MsgBox – for a quick pop-up, but it halts execution.
  • Writing to a text file – using Open and Print # statements for a permanent log.

For most quick checks, the Immediate Window is the fastest tool. For larger debugging sessions, combining it with breakpoints and the Locals Window is the standard approach.

Frequently Asked Questions

Why is my Immediate Window not showing?
Press Ctrl+G while in the Visual Basic Editor. If it still does not appear, go to View → Immediate Window. It may be hidden behind another pane; look for its title bar at the bottom of the VBE.

Can I run a whole macro from the Immediate Window?
Yes. Just type the macro name and press Enter, e.g. MyMacro. If the macro is in a different module, you may need to qualify it, like Module1.MyMacro, unless it is public.

What does the question mark (?) mean in the Immediate Window?
It is shorthand for Print. It tells VBA to evaluate the expression that follows and output the result to the Immediate Window. Without it, a line like 2+2 would just be ignored or cause an error.

How do I clear the Immediate Window?
Select all the text with Ctrl+A and press Delete. There is no built-in “clear� button, but you can also close and reopen the window to start fresh.

Does the Immediate Window work in all Office applications?
Yes, the VBE is the same across Excel, Word, Access, PowerPoint, and Outlook. The Immediate Window works identically, though the object model differs (e.g., ActiveSheet is Excel-specific).

Can I use the Immediate Window to change a cell value while a macro is paused?
Yes. If you are paused at a breakpoint, you can type Range("A1").Value = 100 and press Enter. The change takes effect immediately, and you can continue running the macro to see how it behaves with the new value.

Related

Formula used
in t | Finish time | min | 50 | 0
in d | Distance | km | 10 | 0 | 100000
out pace | Average pace | min/km | t / d | 2
out speed | Average speed | km/h | d / (t / 60) | 2

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →