Excel like a finance pro.
← The libraryPractice · 2 questions →
VBA · User interaction
MsgBox
Shows a message and optionally asks Yes/No.
Daily driverDifficulty 900 · Capable
When to use it
MsgBox shows a message with an OK button, or asks a Yes/No question and returns which button was pressed.
The code
- Code
If MsgBox("Delete rows?", vbYesNo) = vbYes Then ...
Worked examples
Notice
MsgBox "Done" → A simple notice
Feedback at the end of a macro.
Confirm
If MsgBox("Delete rows?", vbYesNo + vbQuestion) = vbYes Then ... → Runs only after Yes
Confirm before destructive steps.
Summary
MsgBox "Rows: " & n & vbNewLine & "Errors: " & e, vbInformation, "Import" → Two lines with a title and icon
Formatted summaries.
Worth knowing
- vbYesNo, vbOKCancel, vbRetryCancel change the buttons; the return values are vbYes, vbNo, vbOK, vbCancel.
- vbNewLine breaks lines; vbTab indents.
- Do not MsgBox inside a loop of 10,000 rows.
Where it goes wrong
- A MsgBox stops the macro until clicked, which blocks unattended runs.
- Long messages are truncated at 1,024 characters.
Related
Learn the moves here — or let Wauvel run them on your numbers.
Meet your AI CFO →One CFO-grade Excel tip a week
A short, practical email for finance operators — functions, shortcuts, and the moves that save an afternoon. Free, unsubscribe anytime.