What is Immediate Window
Immediate Window is a small box in the Visual Basic Editor that you can use to execute a single line of code and get an instant result of that. In simple words, instead of executing your code directly in Excel, you can run a macro line to what it returns. It’s quite useful when you are debugging a code.
When you open the visual basic editor (Alt+ F11), you can see the immediate window at the bottom.
But, if it’s not there then you need to activate it from the edit menu, or you can also use the keyboard shortcut key Control + G.
And if you want to unlock it, click and hold the title bar and drop it and outside of the VB editor.
What is Debug.Print
Debug.Print is a command that you can use to execute a single line of code and get the result of that line in the Immediate Window. In simple words, when you use debug.print command at the starting of the line of code and then execute it, VBA shows the result of that line in the immediate window.
Imagine, you want to know which font color is applied A1. In that case, you can use the following line of code it starts with Debug.Print and then code to get the font color.
Now when you run this code, you get the result in the immediate window, like below:
Executing a Line of Code
Apart from using the debug.print you can directly execute a line of code from the immediate window. Let’s say if you want to enter a value in cell A1 you can directly type the following code in the immediate window, and after that, hit ENTER.
Immediate Window executes a single line of code at a time. So, you need to hit enter each line of code that you want to run.
Run a Macro Directly from the Immediate Window
You can also run a macro directly from the immediate window using the macro name. All you need to do is type the name of the macro and then hit enter.
Make sure to define the arguments within the immediate window if you have any.
Asking Quick Questions
You can also ask questions directly into the immediate window. What I’m trying to say is you can directly write a line of code in the immediate window and use a question mark to get the result.
Let’s say if you want to know the value that you have in cell A1, in that case, you can type the following line of code into the immediate window and hit enter.