Help with a message box with two options for the user which will run different code dependent on the option chosen

Rich_B

Board Regular
Joined
Aug 16, 2014
Messages
239
Hi

As per the title, I need a message box with two options for the user which will run different code dependent on the option chosen.

So for example:

The user clicks a button and is presented with two options in a message box "Option 1" and "Option 2". If option 1 is selected a certain piece of code executes. If option 2 is selected a different piece of code executes.

I'm envisioning a standard message box where I am able to edit the text on the two buttons to say "Option 1" and "Option 2". However, if there is an alternative or a better way of achieving the same result then I am always open to suggestions.

Thank you

Excel 2007
Win 8.1
PC
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
You can get a message box with a 'Yes' or 'No' option that can do what you want.
Code:
Sub t()
Dim ans As Variant
ans = MsgBox("Do you want to say hello?", vbYesNo, "CHOOSE YES OR NO")
    If ans = vbYes Then
        Yes
    Else
        No
    End If
End Sub


Sub Yes()
   MsgBox "Hello"
End Sub


Sub No()
    MsgBox "Bye"
End Sub

You can use the narrative of the message box to instruct the use on how to respond with the Yes or No option.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,338
Messages
6,124,351
Members
449,155
Latest member
ravioli44

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top