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.
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.
To open Immediate Window, click on “View” tab and select “Immediate Window” option. You can even press “CTRL+G” to open 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.
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.
Please log in again. The login page will open in a new tab. After logging in you can close it and return to this page.