+ Reply to Thread
Results 1 to 11 of 11

Dropdown box on user form to select macros

  1. #1
    Registered User
    Join Date
    01-17-2013
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    14

    Dropdown box on user form to select macros

    Hi -

    I am new to the forum and between beginner to intermediate knowledge of VBA. I have been searching through the forum but have not been able to find my answer. I have a number of macros that I wrote (30 of them) and assigned them to buttons on my first sheet. I actually need to write many more, so I wanted to remove all of the buttons and use a Userform with a dropdown that showed the macros. The user would select the macro they want to run, be prompted for a confirmation and then the macro would continue to run.

    I would really appreciate any help.

    Thanks in advance.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Dropdown box on user form to select macros

    Do you have a list of the macro names?

    By the way, what do all these macros do?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    01-17-2013
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Dropdown box on user form to select macros

    An example of the macro names are CreditUnion1, Bank1, etc... The first page has all of the macro buttons, the second page contains data. When the user selects the macro it filters the data on the second page based on institution ID, association ID, Name, etc... After it filters the data it copies the data to a new workbook then saves that to text file on a network drive to be imported into another program then notifies the user that it has completed.

  4. #4
    Registered User
    Join Date
    01-17-2013
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Dropdown box on user form to select macros

    What I am looking to do, or am envisioning, is a Userform with a dropdown, the macros appear in the dropdown. The user selects the macro and has to press a Run button.

    Thanks again.

  5. #5
    Forum Contributor
    Join Date
    05-05-2009
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010 and 365
    Posts
    113

    Re: Dropdown box on user form to select macros

    One way to do it.



    Create a userform with a single treeview control


    Code:


    Please Login or Register  to view this content.




    Three columns in the Macros worksheet.

    Group
    Description
    Macro

    You could skip group if you want to and just go with description and macro. Or just macro for that matter.


    The on error resume next is a little cheesy but it works. Would be cleaner to check if the node exists first and only add it if it doesn't exist.


    The nice thing about doing it this way is that if you want to add macros, alll you need to do is add an entry in the macros worksheet. Just be careful because the macro name listed in the worksheet must be exact.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Dropdown box on user form to select macros

    FISMitch

    Do these macros basically do the same thing but with different criteria/user input?

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Dropdown box on user form to select macros

    Hi FISMitch

    Create a UserForm with a ComboBox (ComboBox1). This Code will populate the ComboBox with a list of all the Macros in the Workbook. You'll need to define further what you wish to do from this point.
    Please Login or Register  to view this content.
    Last edited by jaslake; 01-17-2013 at 11:15 PM.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  8. #8
    Registered User
    Join Date
    01-17-2013
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Dropdown box on user form to select macros

    Cyclops and Jaslake - Thank you! I tested and will be using the Treeview as Cyclops suggested. I have one more question, how do I set up child nodes. At least that's what I believe they are called. Basically, if I several groups, an example of two groups are Banks and Credit Unions, and they need to be filtered in several different ways. I would like the parent node to say Bank then the child nodes that are related to them to say macro 1, macro 2, etc... and the same set up for Credit Unions.

    Thanks in advance.

  9. #9
    Registered User
    Join Date
    01-17-2013
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Dropdown box on user form to select macros

    After a little more playing around with the Treeview and how it populates I figured it out. All I had to do was use the the same group name, put in whatever description I wanted and make sure I had a unique macro name.

    I want to thank you all very much.

  10. #10
    Forum Contributor
    Join Date
    05-05-2009
    Location
    Wisconsin
    MS-Off Ver
    Excel 2010 and 365
    Posts
    113

    Re: Dropdown box on user form to select macros

    Sorry for not responding. Thought you had things worked out. The treeview control is pretty cool but there's not a lot of documentation readily available. It's not in the standard help.

    The thing I like about pulling the names from the sheet is that it makes it possible for someone that doesn't know anything about code to update the list if new macros are added or old ones removed. It probably also makes it a little easier to update yourself.



    I think you can add pictures fairly easily too.

  11. #11
    Registered User
    Join Date
    01-17-2013
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Dropdown box on user form to select macros

    Cyclops -

    Thanks again. I ended up wit about 30+ macros and the treeview was the way to go.

    FISMitch

+ Reply to 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