Two windows useful for debugging are the Immediate window and the Watch window. We'll look at the Immediate window for now, and come back to the Watch window in Chapter 5.
The Immediate window allows you to enter VBA commands and immediately see the results, even if your code isn't running. Simply click inside the window and start typing:
The question mark (?) is a short form for the PRINT command. It will display the results of any formula you give it. As you write your program, you can include the command Debug.Print to display messages in the Immediate window as your program runs. These messages are never seen by the user (unless they are viewing the VBE).
Example:
Debug.Print "I'm about to exit the loop"
Instead of popping up dialog boxes explaining what part of the program is being executed, you can silently output to the Immediate window and examine the messages after. Be sure to remove the debug statements when that section of code is working correctly.
You can also output the value of variables or objects:
Debug.Print Selection.FormulaR1C1
Debug.Print "The value is now " & currentValue