I managed to make userform with search textbox and listbox to display the search result
the current case is that the search result of search textbox "TextBox26" (the first 10 columns of the table in DT sheet ) are displayed in the listbox1, if textbox26 is clear then the listbox is clear
what i need is that all the record are displayed in the listbox by default and then the search box only filter the record displayed in the list box
i mean when the search box is clear the listbox displays all the records and the search box is used to filter this records
the code in the search box "TextBox26" is as follow
Private Sub TextBox26_Change()
Dim a, i As Long, temp
Me.ListBox1.Clear
If Me.TextBox26 = "" Then Exit Sub
temp = LCase$(Me.TextBox26)
a = Sheets("DT").ListObjects("DT.Data.Table").DataBodyRange.Value
With Me.ListBox1
.ColumnCount = 15
For i = 1 To UBound(a, 1)
If (LCase$(a(i, 1)) Like "*" & temp & "*") + (a(i, 2) Like "*" & temp & "*") + (a(i, 3) Like "*" & temp & "*") + (a(i, 4) Like "*" & temp & "*") Then
.AddItem
.List(.ListCount - 1, 0) = a(i, 1)
.List(.ListCount - 1, 1) = a(i, 2)
.List(.ListCount - 1, 2) = a(i, 3)
.List(.ListCount - 1, 3) = a(i, 4)
.List(.ListCount - 1, 4) = a(i, 5)
.List(.ListCount - 1, 5) = a(i, 6)
.List(.ListCount - 1, 6) = a(i, 7)
.List(.ListCount - 1, 7) = a(i, 8)
.List(.ListCount - 1, 8) = a(i, 9)
.List(.ListCount - 1, 9) = a(i, 10)
End If
Next
End With
End Sub
Bookmarks