Display the closest results in list box

yazan

New Member
Joined
Aug 1, 2021
Messages
14
Office Version
  1. 365
Platform
  1. Windows
Hello guys,
i have this code to search for textbox1 value in sheet1, but this code is only showing 100% matched value
my problem is : i want if textbox1.value = "jo" then
listbox1 results are each cell contains "jo"
any solution ?
_________________________________________________________________________
Dim r As Long
For r = 2 To Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
If Trim(Me.TextBox1.Value) = Trim(Sheet1.Cells(r, 1).Value) Then
With Me.ListBox1
.AddItem
.List(.ListCount - 1, 3) = Sheet1.Cells(r, 1).Value
.List(.ListCount - 1, 2) = Sheet1.Cells(r, 56).Value
.List(.ListCount - 1, 1) = Sheet1.Cells(r, 9).Value
End With
End If
Next r
_________________________________________________________________________
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
VBA Code:
Dim SearchTerm as String
SearchTerm = LCase(Me.TextBox1.Value)
For r = 2 to Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    If LCase(CStr(Sheet1.Cells(r, 1).Value)) Like ("*" & searchTerm "*") Then
        ' etc
    End If
Next t

Omit the second asterisk if you want only words that start with "jo"
 
Upvote 0
Solution
VBA Code:
Dim SearchTerm as String
SearchTerm = LCase(Me.TextBox1.Value)
For r = 2 to Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    If LCase(CStr(Sheet1.Cells(r, 1).Value)) Like ("*" & searchTerm "*") Then
        ' etc
    End If
Next t

Omit the second asterisk if you want only words that start with "jo"
thank you but i want if it's contain jo not only if its start with it
 
Upvote 0

Forum statistics

Threads
1,215,425
Messages
6,124,824
Members
449,190
Latest member
rscraig11

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