• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Filter listbox 1 and results in listbox 2

Belleke

Well-Known Member
Hello everybody,
I am looking for some VBA code, if you click in Listbox 1 the results should be in Listbox 2
Sample file attached.
If I click a Licences plate in LB_02, I need the results in LB_03.
Please advice
 

Attachments

  • Garage Werkmap.xlsb
    44.3 KB · Views: 17
Hi,
I found the solution
Code to fill listbox 1
Code:
sn = [nummerplaten]
With CreateObject("scripting.dictionary")
  For i = 1 To UBound(sn)
    .Item(sn(i, 1)) = ""
  Next i
  LB_02.List = .keys
End With
(Nummerplaten is a named range)
Code to fill listbox 2
Code:
With LB_03
        .List = [invoer].Value
        .ColumnCount = [invoer].CurrentRegion.Columns.Count
        .ColumnWidths = "40;70;70;110;"
End With
and
Code:
Private Sub LB_02_Click()
Dim sn, i As Long, c00 As String
sn = Sheets("Invoer Gegevens").Cells(2).CurrentRegion
      For i = 2 To UBound(sn)
      If sn(i, 2) = LB_02.Column(0) Then c00 = c00 & "|" & i
      Next
        If c00 <> "" Then
          LB_03.List = Application.Index(sn, Application.Transpose(Split(0 & c00, "|")), Split("1|2|3|4", "|"))
        Else
          LB_03.Clear
        End If
End Sub
(see the example in the first post)
 
Back
Top