Debug.Print “The Fine Print”

If you have used VBA for more than just recording Macros in Excel, you probably know about Debug.Print, so I won’t go into the usual stuff, but rather tell you about some of the lesser known features of Debug.Print.

A) Converting ? to Print

If you are lazy (And it takes a lazy programmer to be a good programmer) then you instead of typing Debug.Print Expression you can simply type ? Expression, and the VBE will convert the ? into Print for you

B) Debug.Print without Newline

If you want to write more than once to the immediate pane without going to the next line, you can end your Print statement with a semicolon ; . You can try it with this code snippet to see how it works:

C) Spacing the result by use of ,

Sometimes it can be useful to get a more table like output from your code. If you include a , in your Print statement, it will act as a TAB to indent the next part of your statement. This works well for strings of fairly equal length, but can look weird otherwise. Take this simple code snippet to list the creation date for all forms in the database:

As you can see from the screenshot below, the time portion of the result is somewhat aligned (Remember what I said about strings of different lengths?)

Tagged with: , ,

Ask a question, leave some feedback, post a reply!

This site uses Akismet to reduce spam. Learn how your comment data is processed.