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
 

Eric W

MrExcel MVP
Joined
Aug 18, 2015
Messages
8,977
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.
 

Joshyd

New Member
Joined
Mar 6, 2019
Messages
17
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!
 

Forum statistics

Threads
1,081,986
Messages
5,362,560
Members
400,681
Latest member
mariscann

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top