Blog/Excel VBA/Message Box Yes / No

VBA Message Box Yes No: Confirm Before Posting Entries

vba message box yes no: MsgBox vbYesNo approval gate before a macro posts journal entries

The vba message box yes no pattern uses MsgBox with vbYesNo to stop a macro before an irreversible step and require an explicit confirmation, not just an assumption that the user meant to proceed.

Prashant Panchal
Prashant Panchal

ACA | FMVA® | 19 Years in Finance

This guide is part of the FinDataPro Excel VBA Workbook Events series.

The MsgBox Yes/No Gate

Wrap the posting logic in a confirmation check:

Option Explicit

Sub PostJournalEntries()
    Dim response As VbMsgBoxResult

    response = MsgBox("Post 14 journal entries to the GL now? This cannot be undone.", _
                       vbYesNo + vbQuestion, "Confirm Posting")

    If response = vbYes Then
        Call RunPostingRoutine
    Else
        MsgBox "Posting cancelled. No entries were changed.", vbInformation
    End If
End Sub

Nothing posts unless the user explicitly clicks Yes — silence, Escape, or the X button all behave as No.

Download the Example Workbook — Free

The working .xlsm file with a sample reconciliation sheet and this confirmation gate already wired up — open it, inspect the code, and replace the demo posting routine with your own.

Enter your email to get instant access — no spam, ever.

Where the Code Goes

This lives directly in the posting macro itself, as the last check before any irreversible write happens. It pairs well with proper error handling around the posting routine itself, so a failure after confirmation is caught rather than silently dropped.

Finance Use Case: An Approval Gate Before Posting

Any macro that writes journal entries, updates a general ledger, or overwrites a prior period's figures should never run silently to completion on a single click. A confirmation gate costs the user one extra click but removes the far more expensive risk of an accidental keystroke or double-click triggering an irreversible posting run.

The failure mode this guards against is mundane but common: a macro assigned to a keyboard shortcut or a button placed too close to another control gets triggered by accident, and without a gate it runs straight through to completion before anyone realises what happened. In a reconciliation or posting macro, that means real journal entries hitting the ledger with nobody having actually decided to post them. One MsgBox call turns that accidental trigger into a harmless, ignorable prompt instead of a posted transaction that now needs to be reversed.

Making No the Safer Default

For genuinely high-stakes actions, make No the button triggered by pressing Enter:

response = MsgBox("Post entries now?", vbYesNo + vbDefaultButton2, "Confirm Posting")

vbDefaultButton2 shifts the default focus to the second button (No), so an accidental Enter press does not post anything.

Common Mistakes

  • Comparing the result against a hardcoded number instead of the vbYes / vbNo constants.
  • Not declaring the result as VbMsgBoxResult, which loses the type safety and IntelliSense the constants provide.
  • Using vbYesNo when the user might need to abort entirely — vbYesNoCancel is the correct choice when a genuine third option exists.
  • Forgetting that closing the box with the X returns the same result as No, so an Else branch must always follow, never assume Yes.

Once the confirmation gate is in place, see Error Handling: On Error GoTo so a failure after Yes is confirmed is caught rather than silently dropped, or Workbook_BeforeClose for a similar confirmation pattern on file close.

Full reference: Microsoft Learn MsgBox function reference.

Frequently Asked Questions

What is the difference between vbYesNo and vbYesNoCancel?

vbYesNo forces a binary decision. vbYesNoCancel adds a third option when the user might need to abort entirely.

How do I compare the MsgBox result correctly?

Compare against vbYes or vbNo, never a hardcoded number — the constants are readable and version-safe.

Can I make No the default button?

Yes — add vbDefaultButton2 to the arguments so Enter triggers No, safer for irreversible actions.

Does closing with the X count as Yes or No?

It counts as No — there is no way to close a vbYesNo box without an implicit answer.

Conclusion

A single MsgBox vbYesNo check turns an irreversible one-click macro into a deliberate, confirmed action. Set vbDefaultButton2 for the highest-stakes routines, and pair the gate with On Error GoTo so a failure after confirmation never goes unnoticed.

Prashant Panchal
Prashant Panchal• ACA | FMVA® | 19 Years in Finance

Prashant Panchal is a Chartered Accountant (ACA) and Financial Modelling & Valuation Analyst (FMVA®) with 19 years of experience in finance, FP&A, and financial modelling across the GCC region. He is the founder of FinDataPro.

Discussion

Leave a Comment

0/2000

Comments are moderated and appear once approved.