I've been using the following code for quite a while and it works just perfectly to filter a listbox based on a Textbox value (code by Ralph).
Private Sub Textbox1_Change()
Dim i As Long
Dim arrList As Variant
Me.ListBox1.Clear
If TMP.Range("A" & TMP.Rows.Count).End(xlUp).Row > 1 And Trim(Me.TextBox1.Value) <> vbNullString Then
arrList = TMP.Range("A1:A" & TMP.Range("A" & TMP.Rows.Count).End(xlUp).Row).Value2
For i = LBound(arrList) To UBound(arrList)
If InStr(1, arrList(i, 1), Trim(Me.TextBox1.Value), vbTextCompare) Then
Me.ListBox1.AddItem arrList(i, 1)
End If
Next i
End If
If Me.ListBox1.ListCount = 1 Then Me.ListBox1.Selected(0) = True
End Sub
I would like to use it with multicolumn Listbox (4 to be accurate A->D). One of the hints in the original post (titled "How to filter listbox values based on a Textbox value") was to replace :
Me.ListBox1.AddItem arrList(i, 1)
with
Me.Listbox.AddItem
Listbox.List(0, 0) = arrList(i, 1)
Listbox.List(0, 1) = arrList(i, 2)
but i can't make it work. I've been stuck on this for days, could you help me get it to work?
Thank you...