VBA InputBox Yes/No Questions: Use MsgBox Correctly

VBA & macros · Updated November 18, 2026

VBA’s standard InputBox cannot display Yes and No buttons; it collects text instead. To ask a true yes-or-no question in Excel VBA, use MsgBox with the vbYesNo button option, then check whether the returned value is vbYes or vbNo.

What VBA InputBox is designed to do

The built-in VBA InputBox function displays a prompt, a text field, and OK and Cancel buttons. Its return value is a string: the text the user entered. That makes it suitable for requests such as a name, date, or short code, but it does not provide a pair of selectable Yes and No buttons.

This difference matters because a text field does not guarantee a clear answer. Someone might type “y,” “yes,” “sure,” or nothing at all. Your code must decide which entries count as yes or no and what to do with every other response. If you only need a decision, a button-based prompt is simpler and less prone to mistakes.

Excel also has an Application.InputBox method, which can restrict the kind of value a person enters—for example, text, a number, or a cell reference. It still is not a Yes/No button dialog. Its Type option validates the input type; it does not turn the prompt into a two-choice confirmation box.

The simplest Yes/No prompt with MsgBox

Use MsgBox with vbYesNo to show the two buttons. The function returns a result that you can compare with the named constants vbYes and vbNo. Adding vbQuestion displays a question-mark icon, while the title argument labels the dialog.

Sub AskBeforeContinuing()
    ' Ask for a decision and store the selected button.
    Dim answer As VbMsgBoxResult

    answer = MsgBox("Continue with this action?", _
                    vbQuestion Or vbYesNo, _
                    "Confirm")

    If answer = vbYes Then
        MsgBox "You chose Yes.", vbInformation, "Result"
    ElseIf answer = vbNo Then
        MsgBox "You chose No.", vbInformation, "Result"
    End If
End Sub

Save a copy of the workbook before running a macro, particularly if you adapt the example to change or delete data. VBA macros cannot be undone with Ctrl+Z. The sample only reports the response; it does not alter worksheet contents.

The first argument is the message, the second combines button and icon options, and the third is the dialog title. The line-continuation character, a space followed by an underscore, lets the call continue on the next line. You can write the call on one line if you prefer. The key detail is comparing the returned result to vbYes, not to the text “Yes.”

Choosing the right buttons and handling the result

Pick buttons that match the actual decision. vbYesNo is appropriate when either answer is a meaningful choice and the user must choose one. If backing out is a distinct third outcome, use vbYesNoCancel. Then handle all three named return values; do not treat Cancel as if it meant No unless that is genuinely the intended behavior.

For a destructive action, make the prompt specific about what will happen. “Delete the selected rows permanently?” is more informative than “Are you sure?” A No response should leave the data unchanged. When using Yes/No/Cancel, Cancel should normally close the decision without proceeding, while No can represent an explicit decision not to perform the action.

  • Use vbYesNo for a required two-way decision.
  • Use vbYesNoCancel if the user needs a separate way to abandon the question.
  • Use the returned constants vbYes, vbNo, and vbCancel in the matching branches.
  • Keep consequential work inside the affirmative branch so it cannot run after No or Cancel.

These constants are clearer and safer than comparing a result with numeric values. Although MsgBox results are represented by numeric constants, writing If answer = vbYes Then makes the code’s meaning apparent and avoids relying on remembered numbers.

If you really need to collect Yes or No as text

Sometimes a text response is required—for example, if the prompt is part of a larger set of typed answers. In that case, use InputBox, normalize the answer, and explicitly reject anything outside the values you accept. The following example accepts “yes” or “no” in any capitalization and ignores spaces at the beginning or end.

Sub ReadYesOrNoText()
    ' Collect text and accept only Yes or No.
    Dim answer As String

    answer = VBA.InputBox("Type Yes or No:", "Your answer")

    Select Case UCase$(Trim$(answer))
        Case "YES"
            MsgBox "You chose Yes.", vbInformation, "Result"
        Case "NO"
            MsgBox "You chose No.", vbInformation, "Result"
        Case Else
            MsgBox "No valid Yes or No answer was entered.", _
                   vbExclamation, "No decision"
    End Select
End Sub

Trim$ removes leading and trailing spaces, and UCase$ makes the comparison case-insensitive by converting the text to uppercase. The Case Else branch catches an empty answer, an unrecognized word, and Cancel. That last point is important: the standard VBA InputBox returns a zero-length string both when the user cancels and when the user submits an empty field. This method cannot reliably tell those two actions apart.

If distinguishing Cancel from a blank response matters, a standard InputBox is the wrong interface. A Yes/No/Cancel MsgBox gives you separate results for the three choices. For a form with more involved choices or instructions, a custom UserForm can provide dedicated controls and validation.

InputBox and Application.InputBox compared

The names are similar, but the functions serve different purposes. VBA.InputBox is the language’s general text-entry dialog. Excel’s Application.InputBox can ask for particular data types, such as a number, text, a logical value, or a range reference. It is useful when a macro needs a user-selected cell or a validated type of entry, not when the goal is to offer Yes and No buttons.

For example, the Type argument of Application.InputBox can be set to 4 for a logical value. That still presents an input dialog with OK and Cancel rather than two labeled Yes and No buttons. Also, Excel’s method returns a Variant, and Cancel is represented by False; when requesting logical input, that can make distinguishing Cancel from a legitimate False value awkward. For a simple decision, MsgBox with vbYesNo communicates the choices more directly.

In short, choose based on the interaction you need: use MsgBox to receive a button selection, and use an InputBox when the user needs to type or select a value. An InputBox is not a hidden alternative way to configure MsgBox buttons.

Common mistakes and how to avoid them

  • Expecting buttons from InputBox: Its standard dialog has a text box and OK/Cancel. Replace it with MsgBox when the user should click Yes or No.
  • Checking for the wrong kind of value: MsgBox returns a result constant, not the string “Yes.” Store the result as VbMsgBoxResult and compare it with vbYes or vbNo.
  • Ignoring a third response: If you use vbYesNoCancel, include a branch for vbCancel. Otherwise, the code may not make the intended outcome clear.
  • Allowing invalid text to proceed: With InputBox, test the response explicitly. Do not assume every nonblank entry means Yes.
  • Putting the action after the decision: Keep the operation that needs confirmation inside the Yes branch. Code after the branches runs regardless of which button was selected unless you control its flow.
  • Assuming a macro can be undone: Ctrl+Z does not reverse VBA changes. Save a separate copy before testing a macro that edits, moves, or deletes information.

During development, test each possible response. For a Yes/No question, verify that Yes takes the intended action and No does not. If you add Cancel, test that path too. A short prompt can control a large operation, so clear wording and a safe non-Yes path are more important than adding extra dialog options.

Where VBA prompts work

VBA macros run in the desktop versions of Excel, including Microsoft 365 for Windows. Excel for the web can open a macro-enabled workbook but cannot run or edit its VBA macros; a user must open the file in desktop Excel to use this kind of prompt. Excel for Mac supports VBA, although some Excel features and operating-system dialog details differ from Windows. The basic VBA distinction remains the same: use MsgBox for a button response and InputBox for typed input.

For a workbook used by other people, consider whether a modal dialog is appropriate. A MsgBox pauses the macro until a button is clicked, which is useful for a deliberate confirmation but can interrupt a longer automated process. Use prompts only when a person’s decision is necessary; if the action can be safely determined from the workbook’s state, a clear worksheet control or other workflow may be less disruptive.

Frequently Asked Questions

Can VBA InputBox have Yes and No buttons?

No. The standard VBA InputBox accepts typed text and offers OK and Cancel. Use MsgBox with vbYesNo for Yes and No buttons.

How do I check whether the user clicked Yes?

Assign the MsgBox result to a variable declared as VbMsgBoxResult, then test If answer = vbYes Then. The result is a button constant, not the text “Yes.”

How do I add a Cancel button?

Use vbYesNoCancel in the MsgBox button options, then handle vbYes, vbNo, and vbCancel separately so each choice has a defined outcome.

Does Cancel in InputBox return an empty string?

Yes. The standard VBA InputBox returns a zero-length string when the user cancels, and also when the user submits an empty response. Those outcomes cannot be distinguished from that return value alone.

Can Excel for the web run a VBA InputBox?

No. Excel for the web does not run VBA macros. Open the workbook in desktop Excel to run a macro that displays an InputBox or MsgBox.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.