Closed Thread
Results 1 to 9 of 9

how to run a macro upon selecting an item from drop-down menu

  1. #1
    Forum Contributor
    Join Date
    01-08-2008
    Posts
    137

    how to run a macro upon selecting an item from drop-down menu

    I have these macros. Lets call them MacroA, MacroB, MacroC. Now I also have this drop-down menu. The drop down manu has a choice of three items: a, b, c,?

    How do I write code to tell excel to: run MacroA when drop-down menu a is selected, run MacroB when drop-down menu b is selected, run MacroC when drop-down menu c is selected

    Please help!

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,265
    Quote Originally Posted by jcavigli
    I have these macros. Lets call them MacroA, MacroB, MacroC. Now I also have this drop-down menu. The drop down manu has a choice of three items: a, b, c,?

    How do I write code to tell excel to: run MacroA when drop-down menu a is selected, run MacroB when drop-down menu b is selected, run MacroC when drop-down menu c is selected

    Please help!
    Here's the simplest way...
    Place this code in the worksheet module, right click on the sheet tab and select view codes,
    copy and paste this code there
    Please Login or Register  to view this content.
    F1 assumes to be the drop down menu

  3. #3
    Forum Contributor
    Join Date
    01-08-2008
    Posts
    137

    did you miss an end if somewhere?

    I tried it, but it didn't work

  4. #4
    Forum Contributor
    Join Date
    01-08-2008
    Posts
    137

    error message

    "block if without end if"

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello jcavigli,

    This macro will run MacroA when the first item is selected, MacroB when the second item is selected, and MacroC when the third item is selected. The only code changes you would need to make are to the cell where the drop down is located and to macro names. The items are marked in blue.
    Please Login or Register  to view this content.
    How to Save a Worksheet Event Macro
    1. Copy the macro using CTRL+C keys.
    2. Open your Workbook and Right Click on the Worksheet's Name Tab for the Worksheet the macro will run on.
    3. Left Click on View Code in the pop up menu.
    4. Paste the macro code using CTRL+V
    5. Save the macro in your Workbook using CTRL+S

    Sincerely,
    Leith Ross

  6. #6
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,265
    Quote Originally Posted by jcavigli
    "block if without end if"
    Hi,
    Then throw another end if in there
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    01-08-2008
    Posts
    137

    Smile thank you Leith Ross and daveexcel

    Thank you so much.

  8. #8
    Forum Contributor
    Join Date
    01-08-2008
    Posts
    137

    write code to execute a Macro for a drop down menu

    I have a drop down menu with two items in it. The drop down menu is located in cell b48. The two items are called "most inclusive" and "least inclusive." Upon selection of "most inclusive" from the drop-down menu I would like to run the following Macros: ReformatInc, eVestmentInc, and InformaInc. Upon selection of "least inclusive" I would like to run the following Macros: Reformat, eVestment, and Informa.

    What is the simplest code one can write that executes these commands? I have tried the select case function and numerous if statments. However, these list menus are a little bit tricky.

  9. #9
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,265
    Quote Originally Posted by jcavigli
    I have a drop down menu with two items in it. The drop down menu is located in cell b48. The two items are called "most inclusive" and "least inclusive." Upon selection of "most inclusive" from the drop-down menu I would like to run the following Macros: ReformatInc, eVestmentInc, and InformaInc. Upon selection of "least inclusive" I would like to run the following Macros: Reformat, eVestment, and Informa.

    What is the simplest code one can write that executes these commands? I have tried the select case function and numerous if statments. However, these list menus are a little bit tricky.
    It would probably be best to call the other macro, before the other macro ends
    so..........
    sub macro1()
    'codewhatever
    macro2
    end sub
    sub macro2()
    'code whatever
    macro3
    end sub

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1