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

excelent

Comment made by: Dale Daleson , 2011-03-28 09:13:32


Very helpfull

Comment made by: Eugene , 2011-05-02 06:10:37


thanks - that was perfect

Comment made by: brandon , 2011-05-18 14:12:46


Many thanks for this help. Really grateful. Heaven

Comment made by: Heaven , 2011-05-31 10:04:50


ok

Comment made by: elshad , 2011-06-08 05:13:11


Its awsome code yar..

Comment made by: murali.p , 2011-08-01 09:31:36


Be careful not to use boolean type for YesOrNoAnswerToMessageBox

Comment made by: Father B , 2011-08-16 22:31:51


Very Helpful. Thanks for sharing knowledge

Comment made by: Mirna , 2011-10-05 15:22:43


Thanks men you save my day :D

Comment made by: KK , 2011-12-18 10:28:53


Thanks, works beautifully.

Comment made by: Stan , 2012-04-15 00:51:54


Very helpful. Very clear. Many thanks!

Comment made by: Iryna Partem , 2012-05-29 15:20:28


sfsdf

Comment made by: welcom , 2012-07-03 14:04:08


thaks you !!!

Comment made by: Isaac , 2012-09-19 18:04:49


my email address is moc.colomboAgmail.co i am a programmer so if needed send me a message. bye

Comment made by: Maurizio Colombo , 2012-09-24 20:57:55


Sub Test() Dim question$, form$ question = "Are you an expert of VBA ?" form = MsgBox(question, vbYesNo, "QUESTION") If form = vbYes Then MsgBox "Congratulations !", , "QUESTION" form = MsgBox(question, vbYesNo, "QUESTION") MsgBox "Learn more VBA !", , "QUESTION" End If End Sub

Comment made by: Jacky , 2012-10-26 20:57:57


Good website tips

Comment made by: Martin , 2013-01-27 13:38:25


And now my coursework is slightly more professional. :D

Comment made by: ProudyC , 2013-03-21 10:42:18


Dear Sir, We would like to introduce our enterprise. With experience from 1975 as owner during 25 years and rest as nvocc and agent of cargoes, today we offer all intl. and global logistic to exportation and importation with customs clearance maritime, air and road, besides the representation of commodities to export all, always with consultation, or being followed primarily a LOI + BCL or RWA, or BG and / or combine the best we can confirm its power to solvency of intended purchases from Brazil ok? Waiting for your positive return. Many thanks and best regards, Alvaro Lopes Business – Logistic and Commodities Fones:. 011 99744 6798(Vivo) - 98382 5154(Tim) or 3857 6713 E-mail:. alvlopessAuol.com.br Skype:. al.business ... Prezados Senhores, Atuamos dentro do setor do comercio exterior desde 75 e sempre dentro dos transportes marítimos, aéreos e rodoviários, por isso oferecemos uma logística global aos senhores, inclusive com os desembaraços aduaneiros em todos os portos e aeroportos brasileiros e fronteiras, como também na atualização de radar. Outrossim, também atuamos na representação de commodities, tais como o açucar e outros do Brasil. Um forte abraço, Alvaro Lopes Business – Logistic and Commodities Fones:. 011 99744 6798(Vivo) - 98382 5154(Tim) e 3857 6713 E-mail:. alvlopessAuol.com.br Skype:. al.business ...

Comment made by: Alvaro Lope , 2013-03-24 15:49:59


hi, how do i exit a yesNo msbox?

Comment made by: Amak , 2013-05-03 20:33:48


i´m new in vb, i made a program and i put a yesNo msgbox before i exit,but if i try to exit the program the yes and no buttons does the same think.

Comment made by: Amak , 2013-05-03 20:51:14


i´m new in vb, i made a program and i put a yesNo msgbox before i exit,but if i try to exit the program the yes and no buttons does the same think.

Comment made by: Amak , 2013-05-03 20:54:44


hb4

Comment made by: sheena , 2014-10-17 03:18:37


Write Comment:

Comment:

two + 3 minus 1=


Your name: