+ Reply to Thread
Results 1 to 7 of 7

items in combobox2 depending on combobox1

Hybrid View

minifreak items in combobox2 depending... 09-15-2012, 08:09 AM
Jacc Re: items in combobox2... 09-15-2012, 08:25 AM
john456852 what happens when "y" is... 09-15-2012, 08:39 AM
minifreak Re: items in combobox2... 09-15-2012, 10:01 AM
HaHoBe Re: items in combobox2... 09-15-2012, 10:15 AM
minifreak Re: items in combobox2... 09-15-2012, 10:46 AM
JBeaucaire Re: items in combobox2... 09-15-2012, 10:52 AM
  1. #1
    Registered User
    Join Date
    08-16-2012
    Location
    Almere
    MS-Off Ver
    Excel 2003
    Posts
    48

    items in combobox2 depending on combobox1

    I'm looking for the correct If Then solution that can add items to combobox2 depending on the choice that's made with combobox1
    So combobox1 has three choices (X, Y, Z). When a user selects X, the 2nd combobox should display A, B and C.
    When a user selects Z in the first combobox, the 2nd should display G, H and I
    Hopefully I explained good enough what I'm looking for and can I expand a working situation myself with other options

  2. #2
    Forum Expert
    Join Date
    09-01-2012
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    2,883

    Re: items in combobox2 depending on combobox1

    Something like this? I was in a hurry so I used whatever came to mind instead of your letters.
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    08-22-2012
    Location
    nj, us
    MS-Off Ver
    Excel 2010
    Posts
    163
    what happens when "y" is chosen?

    Depending combo boxes.xlsmHere is file
    i modified other guy's . imade it correct
    no errors!
    Last edited by JBeaucaire; 09-15-2012 at 10:01 AM.

  4. #4
    Registered User
    Join Date
    08-16-2012
    Location
    Almere
    MS-Off Ver
    Excel 2003
    Posts
    48

    Re: items in combobox2 depending on combobox1

    thx sofar for the help but is it possible to use this in a userform ??
    so when I press a button on Sheet1, the userform opens and inside this form there are the comboboxes visible

    Quote Originally Posted by john456852 View Post
    what happens when "y" is chosen?
    I'm still figuring out all the options that should be available but if I have a start I can modify all the options later myself
    Last edited by minifreak; 09-15-2012 at 10:09 AM.

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: items in combobox2 depending on combobox1

    Hi, minifreak,

    the normal to attach to the button is simply the call the userform:

    Sub CallUF()
    UserForm1.Show
    End Sub
    Behind the userform place the following code
    Private Sub ComboBox1_Change()
    With ComboBox2
      .Clear
      .ListIndex = -1
      Select Case ComboBox1.Value
        Case "X"
          .AddItem "X 1"
          .AddItem "X 2"
          .AddItem "X 3"
        Case "Y"
          .AddItem "Y 1"
          .AddItem "Y 2"
          .AddItem "Y 3"
        Case "X"
          .AddItem "Z 1"
          .AddItem "Z 2"
          .AddItem "Z 3"
      End Select
    End With
    End Sub
    
    Private Sub UserForm_Activate()
    ComboBox2.ListIndex = -1
    With ComboBox1
      .Clear
      .AddItem "X"
      .AddItem "Y"
      .AddItem "Z"
    End With
    End Sub
    Please alter the names to suit. Within the Select Case you can add other or more items if wanted.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  6. #6
    Registered User
    Join Date
    08-16-2012
    Location
    Almere
    MS-Off Ver
    Excel 2003
    Posts
    48

    Re: items in combobox2 depending on combobox1

    Thx Holger,

    Now I see how the code needs to be written and how it works, I think I can use it very much to create a userform with comboboxes but also maby some more comboboxes
    You all helped me a lot !!

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: items in combobox2 depending on combobox1

    If that takes care of your question, please select Thread Tools from the menu above and mark the thread as solved. Thanks.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ 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