VBA Message Box Yes or No MsgBox




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


Thanks for the code it really has helped me too

Comment made by: Kelvin , 2015-03-26 08:47:08


i dont understand this

Comment made by: arezdo , 2015-06-06 13:43:38


piwpiw

Comment made by: piwpiw , 2015-06-08 12:00:02


mac makeup kit wholesale Big Discount Free Shipping XX2HZ 764 - Danhostel Fredensborg Kursuscenter mac steamy eyeshadow-apqY0Dmz38 - Notebook.com.tr wholesale mac eyelashes-WSiTfDBKM8 Mac Professional Makeup Kit-M57D9QSEy2 IT-Consultant - Christian Gnoth how do you clean mac makeup brushes-5wLmZ0ohiR - Notebook.com.tr wholesale mac online products-DJ5cURUctY Waterhouse Feeds 4AUDYT [url=http://4audyt.pl/mac-sculpt-powder-mjvuyk9umr/]4AUDYT[/url]

Comment made by: 4AUDYT , 2015-07-29 17:37:07


The Yes No Button defaults to Yes. How can I default it to No? Thanks.

Comment made by: Mike Virostko , 2015-10-12 20:53:15


Nice Bro

Comment made by: Gski Sandude , 2016-02-19 11:13:02


Thanks

Comment made by: gg , 2016-03-07 09:30:53


actually i want inputbox in my macro if i type no vba should stop and if i type yes then vba programe execute for further process

Comment made by: mohammed azam , 2016-08-13 12:14:47


Very useful ... thanks

Comment made by: KM , 2016-11-02 11:15:20


Brilliant!

Comment made by: Subhash Choudahary , 2016-11-25 09:00:08


Helped me, thanks

Comment made by: Francis , 2017-03-28 08:45:46


deeznuts 21 6969 meme

Comment made by: Anonymouse , 2017-10-02 13:48:26


Commend made by: Anonymouse , 2017-10-02 13:50:00

Comment made by: Anonymouse , 2017-10-02 13:49:59


Comment made by: Anonymouse , 2017-10-02 13:51:00

Comment made by: ^ you're so bad at this , 2017-10-02 13:51:00


Tahk you very much!

Comment made by: Lorgid , 2018-02-19 22:32:49


your method of explaining the whole thing in this paragraph is genuinely good, all be able to effortlessly know it, Thanks a lot. Regards: Eve Hunt

Comment made by: Eve Hunt , 2019-04-04 09:14:22


"Wow that was unusual. I just wrote an extremely long comment but after I clicked submit my comment didn’t appear. Grrrr… well I’m not writing all that over again. Anyhow, just wanted to say great blog" darknetmarketslink.com

Comment made by: Victoria Tegg , 2019-04-16 08:54:57


I absolutely love your site.. Pleasant colors & theme. Did you build this site yourself? Please reply back as I’m looking to create my very own website and would like to find out where you got this from or what the theme is named. Cheers darknetmarketslink.com

Comment made by: Victoria Tegg , 2019-04-26 08:21:32


I think I will start with windows, I never see anyone editing the bios in Linux based OS's such as Eth or Pimp OS so I doubt i'd be sure where to start off. Is there nothing you can do to automatically restart when power is attached and then automatically start mining on bootup? " Ragerds:Moses Brodin

Comment made by: Moses Brodin , 2019-05-06 09:04:02


Okay, so you've explained what SMOS does and how to set up a basic rig, what about the people out there that don't know about the fees of this software, how to link to pools with it or how to set up the wallets for each of the algos available for this software. This 'how to use' is sorely lacking in a lot of information people need before they can even use it. I'm mining with other software but if I were new to mining and followed your how to guide here I'd have set up smos that isn't linked to my mining pool and would have no idea what wallets to link to, or where they are available from Ragerds:Moses Brodin

Comment made by: Moses Brodin , 2019-05-07 05:14:54


Write Comment:

Comment:

two + 3 minus 1=


Your name: