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 find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
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,214,789
Messages
6,121,593
Members
449,038
Latest member
Arbind kumar

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