VBAString Tip 2: Excel VBA Msgbox Yes No


This is how to add a msgbox with a yes and no prompt to your Excel worksheet.

Just add a button to your worksheet and then add the following code to its “Click” event:

Sub Button1_Click()

    Dim intAnswer As Integer
    
    intAnswer = MsgBox("Would you like to close the application.", vbYesNo, "Please Confirm")
    
    Select Case intAnswer
        Case vbYes
             MsgBox "The application will close now", vbInformation, "Notice"
             Application.Quit
        Case vbNo
            MsgBox "Continue..."
            
            Exit Sub
            
    End Select
    
End Sub

Let me know if you have any questions

[simple_contact_form]