Search in textbox to display listbox result

van0912

New Member
Joined
Jul 27, 2022
Messages
16
Office Version
  1. 2016
Platform
  1. Windows
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?

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!!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,214,585
Messages
6,120,399
Members
448,957
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top