+ Reply to Thread
Results 1 to 4 of 4

Thread: Dependent lists in Userform

  1. #1
    Registered User
    Join Date
    02-01-2010
    Location
    Paris
    MS-Off Ver
    Excel 2007
    Posts
    6

    Dependent lists in Userform

    Hi all.

    I'm hoping someone can help me with a userform problem. I've taken some code I found on this forum, but I'm having difficulty changing it to do what I need

    Is it possible to use a formula like index/match on vba code? I would like to select a town with the first combobox and then to have the second combobox display all the clients that I have on that particular town.

    I have attached the file so you can see what I'm trying to do. When I select the first one, It seems to work but not for the other items on combobox1.

    Thanks,
    Arlete
    Attached Files Attached Files

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: Dependent lists in Userform

    Try this instead:
    Private Sub ComboBox1_Change()
        Dim Col As Long
        Dim blnHeaderRow As Boolean
        Dim cl As Range
        Col = 3
        With Feuil1
            .Range("A1").CurrentRegion.AutoFilter field:=Col, Criteria1:=Me.ComboBox1.Value
            Me.ComboBox2.Clear
            For Each cl In .AutoFilter.Range.Columns(Col).SpecialCells(xlCellTypeVisible)
                If blnHeaderRow = False Then
                    blnHeaderRow = True
                Else
                    Me.ComboBox2.AddItem .Cells(cl.Row, 1).Value
                End If
            Next cl
            .Range("A1").CurrentRegion.AutoFilter
        End With
    End Sub
    
    Private Sub UserForm_Activate()
        Dim cl As Range
        Dim n As Long
        Dim colCites As Collection
        Set colCites = New Collection
        Set rComboSource = Feuil1.Range("C2:C14")
        On Error Resume Next
        
        For Each cl In rComboSource
            colCites.Add cl.Value, cl.Value
        Next cl
        For n = 1 To colCites.Count
            Me.ComboBox1.AddItem colCites(n)
        Next n
    End Sub

  3. #3
    Forum Guru Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    5,590

    Re: Dependent lists in Userform

    Missed the boat again.

    Anyhow as I have amended your workbook here it is.

    Is that what you require?
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    02-01-2010
    Location
    Paris
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Dependent lists in Userform

    Thank you very much to bothn of you. Works perfectly

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0