Running a Macro based on a Value through a Command Button

Joshyd

New Member
Joined
Mar 6, 2019
Messages
17
Hi,

Here is the problem in a nutshell. I Made several macros that create emails. Basically, I have a drop down list that has the title of each of these emails. I would like there to be a command button adjacent to this drop down list that, when clicked, will run the macro for the corresponding entry on the drop down list.

Example:

If "email 1" is selected from the list, when the button is pressed, the macro "make_email_1" is run.

All help is much appreciated.

Thanks,
Josh
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
There are several ways to do this, probably the easiest is to write another macro that does the selecting:

Code:
Sub Email_Selector()


    Select Case Range("A1").Value
        Case "email 1": Call make_email_1
        Case "email 2": Call make_email_2
        Case Else: MsgBox "Unknown email type"
    End Select
End Sub
Change the A1 to where your drop down list is. Then put your button on the sheet and set its macro to Email_Selector.
 
Upvote 0
Thank you so much Eric! That is exactly what I was doing, as it turns out, I had a space at the end of me "email 1" and I never thought to put in an option with an error box so I did not get why it was failing. Thank you for reminding me of an important practice!
 
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,218
Members
448,554
Latest member
Gleisner2

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