Excel VBA Debug Print: How to Do It?

In this article, I’ll show you how you can debug print in VBA in Excel. You’ll learn to open the immediate window and debug print a complete code, a line of code, or the value of a particular variable in the window.


Excel VBA Debug Print (Quick View)

Debug Print in Excel VBA


Download Practice Workbook

Download this practice workbook while you are reading this article.


4 Effective Ways to Perform Debug Print in Excel VBA

So, no more delay. Let’s see how we can debug print through VBA in Excel.

1. Open the Immediate Window to Debug Print in Excel VBA

In order to debug print in VBA, first, you have to open the Immediate window. To do that, press ALT + F11 to open the Visual Basic window.

VBA Window to Debug Print in Excel VBA

Then press CTRL + G on your keyboard. The Immediate window will open.

Immediate Window to Debug Print in Excel VBA

Related Content: Excel VBA: Print UserForm to Fit on a Page (2 Methods)


2. Debug Print a Complete Code in the Immediate Window in Excel VBA

Now we’ve learned to open the Immediate window. Let’s see how can debug print the output of a complete VBA code in the window.

Let’s have a VBA code that takes two integers as variables A and B, and returns their sum in variable C.

Sub Debug_Print()

A = 10

B = 15

C = A + B

End Sub

Now to print the value of C in the Immediate window, you have to insert this line.

Debug.Print C

Debug Print in Excel VBA

Now, if you run the code, you’ll find the value of C (10+15 = 25) in the Immediate window.

Debug Print in Excel VBA

Read More: VBA Code for Print Button in Excel (5 Examples)


Similar Readings:


3. Debug Print a Line of Code in the Immediate Window in VBA

In the previous example, we saw how we can print the output of a code in the Immediate window by the debug.print command.

But you can directly write a line of code in the Immediate window and run it. For example, here I’ve written this line of code in the Immediate window.

Debug.Print "This is Immediate Window."

Now press ENTER on your keyboard. The line will be executed and you’ll find the output in the next line of the window.

Writing Code in Immediate Window in VBA to Debug Print

Read More: How to Print Excel Sheet with Lines (3 Easy Ways)


4. Debug Print in Break Mode in the Immediate Window in Excel VBA

You can also debug print the value of a particular code in the Immediate window. But to do that, you have to go to the break mode of VBA.

For example, in the following figure, the code is in the break mode from in the line:

C = A + B

Break Mode Debug Print in Excel VBA

Break mode means, while running the code, that particular line won’t be executed.

Now, we can debug print the value of any variable in the Immediate window.

For example, to print the value of the variable B, insert this line of code in the Immediate window:

Click ENTER. And you’ll find out the value of B displayed. That’s 15.

Related Content: How to Print Selected Area in Excel on One Page (3 Methods)


Things to Remember

Debug Print is nothing but displaying a particular value in VBA in the Immediate window. In case, you don’t want to use debug print, you can use the Message Box in VBA.


Conclusion

So, these are the methods to use debug print in VBA. Do you have any questions? Feel free to ask us. And don’t forget to visit our site ExcelDemy for more posts and updates.


Related Articles

Rifat Hassan

Rifat Hassan

Hello! Welcome to my profile. Here I will be posting articles related to Microsoft Excel. I am a passionate Electrical Engineer holding a Bachelor’s degree in Electrical and Electronic Engineering from Bangladesh University of Engineering and Technology. Besides academic studies, I always love to keep pace with the revolution in technology that the world is rushing towards day by day. I am diligent, career-oriented, and ready to cherish knowledge throughout my life.

We will be happy to hear your thoughts

Leave a reply

ExcelDemy
Logo