+ Reply to Thread
Results 1 to 7 of 7

populate 4 combobox based on dependant combobox

Hybrid View

roninn75 populate 4 combobox based on... 08-03-2013, 03:53 AM
blue.chio Re: populate 4 combobox based... 08-06-2013, 02:50 AM
p_nayak268 Re: populate 4 combobox based... 08-06-2013, 04:59 AM
roninn75 Re: populate 4 combobox based... 08-06-2013, 05:52 AM
blue.chio Re: populate 4 combobox based... 08-06-2013, 05:28 AM
p_nayak268 Re: populate 4 combobox based... 08-06-2013, 05:33 AM
blue.chio Re: populate 4 combobox based... 08-06-2013, 06:09 AM
  1. #1
    Registered User
    Join Date
    11-03-2010
    Location
    cape town
    MS-Off Ver
    Excel 2007
    Posts
    27

    populate 4 combobox based on dependant combobox

    good day

    i have a sheet with various columns eg. DISTRICT, TOWN, NAME, RATE. In another workbook i have a form with which i am calling the values in the first workbook.
    i wish to populate the first combobox with the values from DISTRICT, the second combobox(TOWN) then needs to go see which values in TOWN is listed against that district in the first workbook and populate that combobox.
    the third combobox then looks at the value selected in the TOWN combobox, go see what names are listed against that in the first workbook and populate the NAMES combobox with those names. lastly, the RATE combobox looks at the value selected in the NAMES combobox, go see what rates are listed against that in the first workbook and populate the RATES combobox with those values...

    any assistance is highly appreciated.

  2. #2
    Forum Contributor
    Join Date
    03-14-2012
    Location
    location
    MS-Off Ver
    Excel 2007
    Posts
    170

    Re: populate 4 combobox based on dependant combobox

    Hi,
    few month ago I had a similar problem, I found this code and helped me. see if it helps you.
    (for the first step, in your first workbook try the code then you'll find a way to read the valus from there...)
    Dim rcat1 As Long, rcat2 As Long, rcat3 As Long, rcat4 As Long
    Private Sub ComboBox1_Change()
        Dim cat1 As String, cat2 As String, cat3 As String, cat4 As String
        
        ComboBox2.Clear
        ComboBox3.Clear
        ComboBox4.Clear
         
        'rcnt = Range("A" & Rows.Count).End(xlUp).Row
        For i = 2 To rcat2
            If Range("a" & i).Value = ComboBox1.Value And Range("a" & i).Value <> Range("b" & i + 1).Value Then
                ComboBox2.AddItem Range("b" & i).Value
            End If
        Next
     End Sub
    Private Sub ComboBox2_Change()
     ComboBox3.Clear
        ComboBox4.Clear
      For i = 2 To rcat3
            If Range("b" & i).Value = ComboBox2.Value And Range("b" & i).Value <> Range("c" & i + 1).Value Then
                ComboBox3.AddItem Range("c" & i).Value
            End If
        Next
    End Sub
    Private Sub ComboBox3_Change()
        ComboBox4.Clear
        For i = 2 To rcat4
            If Range("c" & i).Value = ComboBox3.Value And Range("c" & i).Value <> Range("d" & i + 1).Value Then
                ComboBox4.AddItem Range("d" & i).Value
            End If
        Next
    End Sub
    Private Sub UserForm_Activate()
        rcat1 = Range("a" & Rows.Count).End(xlUp).Row
        rcat2 = Range("b" & Rows.Count).End(xlUp).Row
        rcat3 = Range("c" & Rows.Count).End(xlUp).Row
        rcat4 = Range("d" & Rows.Count).End(xlUp).Row
        For i = 2 To rcat1
            If Range("a" & i).Value <> Range("a" & i + 1).Value Then
                ComboBox1.AddItem Range("a" & i).Value
            End If
        Next
    End Sub
    blue

  3. #3
    Registered User
    Join Date
    05-21-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: populate 4 combobox based on dependant combobox

    Hi Blue,

    I am looking for similar kind of solution, so i usded your code. Unfortunately it did not work. It could only populate the 'Combobox1'.Other Comboboxed failed to populate.
    Finally, based on all the 4 Combobox selection, I want those rows to be populated in the 'ListBox'. I have attached the excel file.

    Someone please help me. I appreciate your time and effor.

    By the way, this is my first post in the forum

    Thank you,
    Pratap
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    11-03-2010
    Location
    cape town
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: populate 4 combobox based on dependant combobox

    thank you Blue, i eventually did this:
        Private Sub BxStaDistrict_AfterUpdate()
            Dim Cl As Range
            Dim ClAddress As String
            Dim coll As New Collection
            Dim itm As Variant
            'if no selection in district quit
            If Me.BxStaDistrict.ListIndex < 0 Then Exit Sub
            With Sheet17
                Set rSource = .Range(.Cells(1, 1), .Cells(.Rows.Count, 1).End(xlUp))
            End With
            With Me
                .BxStaName.Clear
                .BxStaOIC.Clear
                Set Cl = rSource.Find(What:=Me.BxStaDistrict.Value, LookIn:=xlValues, LookAt:=xlWhole)
                If Not Cl Is Nothing Then
                    ClAddress = Cl.Address
                    Do
                        On Error Resume Next
                        coll.Add Item:=Cl.Offset(0, 1).Value, Key:=CStr(Cl.Offset(0, 1).Value)
                        On Error GoTo 0
                        Set Cl = rSource.FindNext(After:=Cl)
                    Loop While Not Cl Is Nothing And Cl.Address <> ClAddress
                End If
                For Each itm In coll
                    .BxStaName.AddItem itm
                Next itm
            End With
        End Sub
    
        Private Sub BxStaName_AfterUpdate()
            Dim Cl As Range
            Dim ClAddress As String
            Dim coll As New Collection
            Dim itm As Variant
            'if no selection in name quit
            If .BxStaName.ListIndex < 0 Then Exit Sub
            With Sheet17
                Set rSource = .Range(.Cells(1, 2), .Cells(.Rows.Count, 2).End(xlUp))
            End With
            With Me
                .BxStaOIC.Clear
                Set Cl = rSource.Find(What:=Me.BxStaName.Value, LookIn:=xlValues, LookAt:=xlWhole)
                If Not Cl Is Nothing Then
                    ClAddress = Cl.Address
                    Do
                        On Error Resume Next
                        coll.Add Item:=Cl.Offset(0, 1).Value, Key:=CStr(Cl.Offset(0, 1).Value)
                        On Error GoTo 0
                        Set Cl = rSource.FindNext(After:=Cl)
                    Loop While Not Cl Is Nothing And Cl.Address <> ClAddress
                End If
                For Each itm In coll
                    .BxStaOIC.AddItem itm
                Next itm
            End With
        End Sub

  5. #5
    Forum Contributor
    Join Date
    03-14-2012
    Location
    location
    MS-Off Ver
    Excel 2007
    Posts
    170

    Re: populate 4 combobox based on dependant combobox

    Hi p_nayak
    Welcome to the forum!
    Accordind to the forum rule 2:
    "2. Don't post a question in the thread of another member -- start your own. If you feel it's particularly relevant, provide a link to the other thread. You may include up to 3 links to other URLs in a single post, no more, so only link to the relevant pages."

  6. #6
    Registered User
    Join Date
    05-21-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: populate 4 combobox based on dependant combobox

    Hi Blue,

    Thanks, I will start a new thread.

    p_nayak

  7. #7
    Forum Contributor
    Join Date
    03-14-2012
    Location
    location
    MS-Off Ver
    Excel 2007
    Posts
    170

    Re: populate 4 combobox based on dependant combobox

    Glad you did it yourself! Thank you for the feedback!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Excel Userform: Populate other controls (i.e. textbox & combobox) based on combobox select
    By MileHigh_PhD in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-22-2013, 04:50 PM
  2. Way to populate combobox rowsource based on previous combobox value
    By subbby in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-08-2012, 12:50 AM
  3. Code to reset combobox dependant on another combobox
    By j.farr3ll in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-08-2011, 08:21 AM
  4. transferring combobox value from one user form to populate combobox on another
    By smartphreak in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-05-2010, 10:12 PM
  5. Replies: 2
    Last Post: 09-14-2009, 08:34 AM

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