Hello,
I would like to use a textbox to show results in a listbox. Problem is I don't know the syntax and how to display data whatever we search in the textbox. In the following code, it displays only value from the middle but I would like to display anything that contains the data enter in the textbox (from beginning, middle or end, lowercase/ uppercase). Does someone know?
Thank you!!
I would like to use a textbox to show results in a listbox. Problem is I don't know the syntax and how to display data whatever we search in the textbox. In the following code, it displays only value from the middle but I would like to display anything that contains the data enter in the textbox (from beginning, middle or end, lowercase/ uppercase). Does someone know?
VBA Code:
Private Sub TextBox50_Change()
Me.TextBox50 = Format(StrConv(Me.TextBox50, vbLowerCase))
Dim sh As Worksheet
Set sh = Sheets("Data")
Dim i As Long
Dim x As Long
Dim p As Long
Me.ListBox4.Clear
For i = 4 To sh.range("H" & Rows.Count).End(xlUp).row 'from row 4 to lastrow with data
For x = 8 To Len(sh.Cells(i, 8)) 'for column 8 "references"
p = Me.TextBox50.TextLength
If LCase(Mid(sh.Cells(i, 8), x, p)) Like Me.TextBox50 And Me.TextBox50 <> "" Then
With Me.ListBox4
.AddItem sh.Cells(i, 8).Value
.List(ListBox4.ListCount - 1, 1) = sh.Cells(i, 10).Value
.List(ListBox4.ListCount - 1, 2) = sh.Cells(i, 13).Value
.List(ListBox4.ListCount - 1, 3) = sh.Cells(i, 15).Value
.List(ListBox4.ListCount - 1, 4) = sh.Cells(i, 18).Value
.List(ListBox4.ListCount - 1, 5) = sh.Cells(i, 19).Value
End With
End If
Next x
Next i
End Sub
Thank you!!