Closed Thread
Results 1 to 10 of 10

How to activate a macro from combo box / list box

  1. #1
    Registered User
    Join Date
    08-08-2008
    Location
    Johannesburg
    MS-Off Ver
    2007
    Posts
    55

    How to activate a macro from combo box / list box

    Hi everyone
    I'm trying to figure out how to activate a macro from combo box or list box.
    But no success.

    I have a list of names:
    AAA
    BBB
    CCC
    111
    222
    333

    That I can view through the combo box.


    I have created a list of macros, that carry the same names,

    AAA
    BBB
    CCC
    111
    222
    333

    The Q is: how can I link each name to its own macro?
    so when chosen, will activate the macro?

    Thanks for the help
    Using Excel 2007.
    Amit Cohen

  2. #2
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650
    Hi Try this if its a "Ciontrol Toolbox" Combobox.
    Please Login or Register  to view this content.
    How do you call a "Macro" (111) ?? I did'nt think you could do that!!
    Regards Mick

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Or maybe
    Please Login or Register  to view this content.

  4. #4
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650
    Hi, Sometimes you can't see the wood for the trees !!!
    Mick

  5. #5
    Registered User
    Join Date
    08-08-2008
    Location
    Johannesburg
    MS-Off Ver
    2007
    Posts
    55

    Wink

    Hi Mick
    Thanks for that, but do have another Q (I'm not an expert..)

    Where exactly do I put the macro code itself?
    I mean, should it be somthing like that:

    Select Case ComboBox1.Value
    Case "AAA"
    Call AAA
    Please Login or Register  to view this content.
    End Select



    Many Thanks!!

    P.S.
    The numbers was just for the example ;-)
    Last edited by davesexcel; 11-30-2019 at 12:53 AM.

  6. #6
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650
    Hi, As "shg" so knowledgeably pointed out, you don't need all that code if you just need to run a "Macro" from a Combobox when the Macro name is the same as the Combobox Box value.
    If you combobox came from the "View" , "Control Toolbar" then do the following:-
    Get the "Control Toolbar" menu on the sheet from "View"--.
    Click the Green triangle icon, this gets the Combobox in Design Mode,
    When you hold the cursor over the "ComboBox" the Cursor changes to Arrow Headed Cross.
    Right Click Select Properties, Find "ListFillRange" enter the Range with you Macro names in i.e.. A1:A5
    Double Click the Combobox, or right click and select "View Code"
    Paste the code into the window, between "Private Sub ComboBox1_Change() " and "End Sub". to end up as shown below:-.
    Please Login or Register  to view this content.
    Click the Green Triangle on the VB Window "Toolbar"
    This will turn the blue square to it's left Dark Blue. You are now in run mode.
    Close VB Window.
    Now when you select a value in your ComboBox the related "Macro" will run. (Hopefully)
    ---------
    If you have a Combobox from the from the "forms" Menu then do the following:-
    Right click, choose "Format Control", "Control", enter range as above in "Input Range"
    Close "Format control"
    Right click, Combobox (DropDown Box), choose, "Assign Macro".
    Select you "Drop down Box" from the Menu, if New choose "New" else choose "Edit".
    Paste the following into the VB window after the words :- "Sub DropDown?_Change()"
    and before "End Sub"
    Please Login or Register  to view this content.
    Close VBWindow.
    On selection of ComboBox value the chosen "Macro will run.
    Hope that's everything
    Regards Mick

  7. #7
    Registered User
    Join Date
    08-08-2008
    Location
    Johannesburg
    MS-Off Ver
    2007
    Posts
    55

    Getting an error..

    Hi Mick
    Thanks for your detailed post.

    I followed your instructions (the 2'nd option)
    The code I've added:
    Please Login or Register  to view this content.
    Then, following comes the macro code.

    But when I activate the macro from the combo box,
    I get this error message:
    Run-time error '1004':
    Unable to get the DropDown property of the worksheet class
    What does it means?
    Can you advice?

    Thx,
    Amit

  8. #8
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650
    Hi,I've copied your code from your last post and it works OK.
    Try Removing that bit of code, replace it with the bit below. It should give you a Msgbox with name of the Drop Down Box.
    see what you get.
    Please Login or Register  to view this content.
    Mick
    Last edited by MickG; 09-06-2008 at 12:29 PM.

  9. #9
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,480

    Select Macro from ComboBox

    Here is an attachment using examples from both posters.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    08-08-2008
    Location
    Johannesburg
    MS-Off Ver
    2007
    Posts
    55

    Thanks ;-)

    Hi Guys
    Thanks so much for your help,
    You saved me a lot of time!!

    Cheers
    A.C.

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. List of files into Combo - Dir(path) function
    By RichardBerry in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-22-2008, 05:45 AM
  2. Reversing List in a Combo Box
    By bluepill in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-21-2007, 07:18 AM
  3. Need a macro to search and remake any list
    By mfrancis in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-21-2006, 04:54 AM
  4. Activate a file in my macro
    By punter in forum Excel General
    Replies: 5
    Last Post: 10-07-2006, 03:38 PM
  5. Macro from List?
    By rufusf in forum Excel General
    Replies: 1
    Last Post: 10-06-2006, 08:35 AM

Tags for this Thread

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