+ Reply to Thread
Results 1 to 3 of 3

dependent combo boxes

Hybrid View

  1. #1
    Registered User
    Join Date
    11-29-2009
    Location
    dubai
    MS-Off Ver
    Excel 2003
    Posts
    56

    dependent combo boxes

    hi,
    Need help on the following,

    My work book has 4 cols (Name, Vendor, Product, Sub Product)

    User Form 1 has 4 combo boxes with same above col names.

    I need a code that does the foll;

    - When Combo Box ‘Name’ is selected - should list the following ‘Unique’ Values from Col 'Name'
    ‘Sales Man 1’ & ‘Sales Man 2’

    - if ‘Sales Man 1’ is selected in Combo Box ‘Name’,
    Combo Box ‘Vendor’ - should list the following ‘Unique’ Values from col 'vendor'
    ‘Vendor 1’ & ‘Vendor 2’

    - if ‘Vendor 1’ is selected in Combo Box ‘Vendor’,
    Combo Box ‘Product’ - should list the following ‘Unique’ Values from col 'Product'
    ‘Product 1’ & ‘Product 2’

    - if ‘Product 1is selected in Combo Box ‘Product’,
    Combo Box ‘Sub Product’ - should list the following ‘Unique’ Values from col 'Sub Product
    ‘SP 1.1’ , ‘SP 1.2’, ‘SP 1.3’

    Thanks
    R
    Attached Files Attached Files
    Last edited by rvc81; 02-26-2011 at 03:53 PM.

  2. #2
    Registered User
    Join Date
    04-14-2010
    Location
    NZ
    MS-Off Ver
    2007,2010
    Posts
    86

    Re: dependent combo boxes

    Try this

    It runs off Workbook_Open at present, though that's easily changed to what-ever you wish.
    borrowed code from here: http://www.excelforum.com/excel-prog...-combobox.html

    Private Sub Workbook_Open()
    UserForm1.agent.Clear
    Sheet1.Range("A1").AutoFilter
    Call FillCombobox(Sheet1.Range("A2", Sheet1.Cells(Rows.Count, "A").End(xlUp)), UserForm1.agent)
    UserForm1.Show
    End Sub
    ------
    
    Private Sub agent_Change()
    UserForm1.vendor.Clear
    If Sheet1.FilterMode = True Then: Sheet1.ShowAllData
    Sheet1.Range("A1").AutoFilter field:=1, Criteria1:="=" & UserForm1.agent.Value
    Call FillCombobox(Sheet1.Range("B2", Sheet1.Cells(Rows.Count, "B").End(xlUp)).SpecialCells(xlCellTypeVisible), UserForm1.vendor)
    End Sub
    -----------
    
    Private Sub vendor_Change()
    UserForm1.product.Clear
    Sheet1.Range("A1").AutoFilter field:=2, Criteria1:="=" & UserForm1.vendor.Value
    Sheet1.Range("A1").AutoFilter field:=3
    Call FillCombobox(Sheet1.Range("C2", Sheet1.Cells(Rows.Count, "C").End(xlUp)).SpecialCells(xlCellTypeVisible), UserForm1.product)
    End Sub
    -----------
    
    Private Sub product_Change()
    UserForm1.subproduct.Clear
    Sheet1.Range("A1").AutoFilter field:=3, Criteria1:="=" & UserForm1.product.Value
    Call FillCombobox(Sheet1.Range("D2", Sheet1.Cells(Rows.Count, "D").End(xlUp)).SpecialCells(xlCellTypeVisible), UserForm1.subproduct)
    End Sub
    --------------
    
    Sub FillCombobox(entRng As Range, cbox As Object)
    Dim cllrng As Range
    Dim toAdd As New Collection
    Dim collItem
    
    On Error Resume Next
    For Each cllrng In entRng
        toAdd.Add cllrng.Value, CStr(cllrng.Value)
    Next cllrng
    On Error GoTo 0
    
    For Each collItem In toAdd
        cbox.Object.AddItem collItem
    Next collItem
    End Sub
    Attached Files Attached Files
    Last edited by Deamo; 02-25-2011 at 07:03 PM.

  3. #3
    Registered User
    Join Date
    11-29-2009
    Location
    dubai
    MS-Off Ver
    Excel 2003
    Posts
    56

    Re: dependent combo boxes

    thanks a lot

+ 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