Office Tip (Advanced) – Different uses of the immediate window

A very useful but often overlooked feature of the Visual Basic Editor in Microsoft Office applications is the Immediate Window which can be quickly accessed by pressing “ALT” + “F11” and then “CTRL” + “G”. This opens up a window which can execute code immediately and display the result even while a macro is running which is why it is often used for debugging a malfunctioning program.

One way to use this is as an interface to ask specific questions by placing a question mark before the enquiry and pressing “Enter” which will then show the result in a new line. I.e. in the following Excel example we are asking this window to display the result of the calculation 5+8/2 which it prints out as 9. We are then asking it to tell us whether cell A1 currently contains any formula which it denies in the next line:


Without the question mark we can actually execute code directly without having to set up a macro one line at a time (that is we can execute multiple lines if we write them in one line separated by a colon). I.e. the following example will write the values 25 and 31 in cells A2 and A3 respectively the moment we press Enter:


Share this tip on