Results 1 to 4 of 4

Thread: Running a Macro based on a Value through a Command Button

  1. #1
    New Member
    Join Date
    Mar 2019
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Running a Macro based on a Value through a Command Button

    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

  2. #2
    MrExcel MVP Eric W's Avatar
    Join Date
    Aug 2015
    Location
    Bountiful, UT
    Posts
    8,659
    Post Thanks / Like
    Mentioned
    42 Post(s)
    Tagged
    5 Thread(s)

    Default Re: Running a Macro based on a Value through a Command Button

    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.
    Cheers,
    Eric

    When you eliminate the impossible, whatever remains, however improbable, must be the truth.

    -Posting guidelines, forum rules, terms of use, FAQs, BB codes, See how to search the forum
    -Post a screen shot with the HTML Maker

  3. #3
    New Member
    Join Date
    Mar 2019
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Running a Macro based on a Value through a Command Button

    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!

  4. #4
    MrExcel MVP Eric W's Avatar
    Join Date
    Aug 2015
    Location
    Bountiful, UT
    Posts
    8,659
    Post Thanks / Like
    Mentioned
    42 Post(s)
    Tagged
    5 Thread(s)

    Default Re: Running a Macro based on a Value through a Command Button

    Glad to help!

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •