We all know that VBA allows us to create Macros in Microsoft Excel which does complex tasks in an easy way. You can create a Macro for tasks which you are supposed to do repeatedly. But, while writing VBA code we come across some issues or errors and finding them would be hard. So, we need to know the debug process to find such errors. Using Immediate Window in VBA helps us to know the value of the variable used in the code, hence making the debugging easy. Excel MVP Jordan shows us how to use Immediate Window in Excel VBA.
Using the Immediate Window in Excel VBA
1 – Enable Developer Tab in Excel
In order to open Visual Basic Editor in Excel, you need to enable the Developer tab in Excel. Next tap on the Developer tab and click on ‘Visual Basic’ option and it would open Visual Basic Editor.
2 – View the Immediate Window
To open Immediate Window, click on “View” tab and select “Immediate Window” option. You can even press “CTRL+G” to open Immediate Window.
3 – See Output in Immediate Window
Once you have enabled Immediate Window, then you can print output of any variable in it. You can execute the VBA program and it would show the output in Immediate Window. In this example, I used ‘Debug.Print’ which prints the value of ‘I’ in Immediate Window. You can explore more functions as such. It also possible to delete the text printed in Immediate Window.
4 – Directly Debug in Immediate Window
Not only you can print values present in the program, you can even directly check values by typing in Immediate Window. Let us say, you want to set the width of selected cell in Excel, then you can type “selection.columnWidth=10”. This would set selected cell width to the given value.
These are just examples and you can explore more by using different functions. There are lot more functions which you can use directly in Immediate Window. Please give it a try.
So, you can debug VBA Program using Immediate Window and get rid of the errors. Give it a try and explore it more.
Let us know how you are using Immediate Window to debug your VBA programs. If you have anything to add, please do share with us through comments.
- Edit Excel Formulas in WORD – Spreadsheet Tips and Tricks - February 17, 2022
- Using the Immediate Window in VBA - April 4, 2017
- Intersection Operator with Named Ranges – Excel Tips and Tricks - October 3, 2016