+ Reply to Thread
Results 1 to 7 of 7

Dynamic dependant VBA drop downs

  1. #1
    Forum Contributor
    Join Date
    04-11-2012
    Location
    Canada
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    100

    Dynamic dependant VBA drop downs

    I have a user form with a two combo boxes wheras one reads 'Main Category' and the other 'Sub Category'.

    To make it simple here is a little preview:

    Main Category: Plumbing
    Sub Category: Showers, Toilets, Doors

    Main Category: Electricity
    Sub Category: Switches, Receptacles, Wires

    The Code of my Main Category is as follows and works fine:

    Please Login or Register  to view this content.
    Is it possible tough to create a code that is dynamic (adding a new item will automatically show up in user form) and dependent (sub category is dependent on value of main category)?

    *I tried Excel Data Validation, but it seems not to comply when using user forms...

  2. #2
    Valued Forum Contributor
    Join Date
    02-04-2009
    Location
    Texas
    MS-Off Ver
    Excel 2016
    Posts
    665

    Re: Dynamic dependant VBA drop downs

    create name lists i.e. MainCategory: Plumbing, Electrical...
    Sub Categories: Switches, Recepticles...

    Then you can create cascading Combo Boxes on your user form.
    Set up the initial Combo Box (MainCategoery) to load when the USer Form Opens,
    Then the next (SubCategory) to Load when the first Cbo changes:
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    04-11-2012
    Location
    Canada
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    100

    Re: Dynamic dependant VBA drop downs

    Thanks a lot. Works perfect! Except some categories have more than one word, but I guess I have to include a SUBSTITUTE function when creating named ranges... Will see if that works...

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Dynamic dependant VBA drop downs

    questionguy,

    Here's an alternate method that doesn't use named ranges. Sample workbook attached. As a side note, the Categories table should always be sorted by Main Category.
    Attached Files Attached Files
    Last edited by tigeravatar; 09-10-2012 at 04:19 PM. Reason: Added side note
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  5. #5
    Forum Contributor
    Join Date
    04-11-2012
    Location
    Canada
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    100

    Re: Dynamic dependant VBA drop downs

    I like it, thanks!!

  6. #6
    Valued Forum Contributor
    Join Date
    02-04-2009
    Location
    Texas
    MS-Off Ver
    Excel 2016
    Posts
    665

    Re: Dynamic dependant VBA drop downs

    Create MainCategory List and name the Range
    Then Create a List for each Subcategory, and name each list a name from the MainCategory List.

  7. #7
    Forum Contributor
    Join Date
    04-11-2012
    Location
    Canada
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    100

    Re: Dynamic dependant VBA drop downs

    Thanks sharing your knowledge people...

+ 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