VBA Message Box Yes or No MsgBox

Code for calling a message box with the option Yes or No and depending on the answer different coding is executed.

Explanation

To call a message box with the option Yes or No and depending on the answer different execute different sub programs is good when trying a more interactive approach with the end-user. By using this function you can choose path of the rest of the program if the user answers yes then a certain code is run and if the user answers no another code is run. Simple and clever!

The VBA Macro Code is available for download at the end of this web page!
 

 

Code

Public Sub MessageBoxYesOrNoMsgBox()

Dim YesOrNoAnswerToMessageBox As String
Dim QuestionToMessageBox As String

    QuestionToMessageBox = "Are you an expert of VBA?"

    YesOrNoAnswerToMessageBox = MsgBox(QuestionToMessageBox, vbYesNo, "VBA Expert or Not")

    If YesOrNoAnswerToMessageBox = vbNo Then
         MsgBox "Learn more VBA!"
    Else
        MsgBox "Congratulations!"
    End If

End Sub

 

 

Download excel file! VBA_Message_Box_Yes_or_No_MsgBox.xls

 
Comments (9)
excelent
9 Sunday, 18 December 2011 10:28
KK
Thanks men you save my day :D
Thanks
8 Wednesday, 05 October 2011 15:22
Mirna
Very Helpful. Thanks for sharing knowledge
-
7 Tuesday, 16 August 2011 22:31
Father B
Be careful not to use boolean type for YesOrNoAnswerToMessageBox
many thanks
6 Monday, 01 August 2011 09:31
murali.p
Its awsome code yar..
sub
5 Wednesday, 08 June 2011 05:13
elshad
ok
Thanks
4 Tuesday, 31 May 2011 10:04
Heaven
Many thanks for this help. Really grateful.

Heaven
awesome
3 Wednesday, 18 May 2011 14:12
brandon
thanks - that was perfect
Very helpfull
2 Monday, 02 May 2011 06:10
Eugene
Very helpfull
ICT - A2
1 Monday, 28 March 2011 09:13
Dale Daleson
excelent

Add your comment

Your name:
Subject:
Comment: