Introduction to Debug.Print and MsgBox
Swipe to show menu
Both let you see a value while your code runs, but they're built for two different audiences, and mixing them up is a common early habit worth correcting deliberately.
Debug.Print
Debug.Print [outputlist]
outputlist— one or more expressions to print, optionally joined with;or&;- No parentheses, no return value — it's a statement, not a function;
- Always writes to the Immediate Window.
Debug.Print total ' one value
Debug.Print "Total: "; total ' semicolon — adds a space between items
Debug.Print "Total: " & total' & — concatenates with no extra space
MsgBox
MsgBox(prompt, [buttons], [title], [helpfile], [context])
MsgBox "Done." ' statement form — no parentheses needed
result = MsgBox("Continue?", vbYesNo, "Confirm") ' function form — parentheses required
Parentheses around MsgBox's arguments are only used when you're capturing a return value. Used as a plain statement (no assignment), parentheses are actually a mistake — MsgBox("Done.") still runs, but the moment you add a second argument without an assignment, MsgBox ("Continue?", vbYesNo) throws a syntax error. Drop the parentheses for statement form, add them only when writing result = MsgBox(...).
What Each One Is Actually For
A simple test: ask who the message is actually for. If the answer is "me, while I'm writing and testing this code," reach for Debug.Print — it costs nothing to leave in temporarily and nothing to remove later, since it never surfaces to anyone using the finished workbook. If the answer is "the person running this macro, right now, who needs to see this," reach for MsgBox — a confirmation prompt, or a "done" message all fall into this category, because they're part of the finished experience rather than a debugging aid.
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat