MhmdHalawi

New Member
Joined
Aug 10, 2018
Messages
6
This is a search and print code, but the problem is that the code only finds results that are 100% like the searched for name or text, can this be tweaked so that it finds almost the same ? for example instead of typing Jonathan i can type Jon

Code:
Sub Button1_Click()Dim lastrow As Long
Dim count As Integer
Dim n As String


lastrow = Sheet3.Cells(Rows.count, 1).End(xlUp).Row
count = 0
y = 2
a = 2
For a = 2 To lastrow
Sheet4.Cells(a, 1).ClearContents
Sheet4.Cells(a, 2).ClearContents
Sheet4.Cells(a, 3).ClearContents
Next a
n = Sheet4.Range("E1")


For x = 2 To lastrow
If Sheet3.Cells(x, 1) Like n Then
Sheet4.Cells(y, 1) = Sheet3.Cells(x, 1)
Sheet4.Cells(y, 2) = Sheet3.Cells(x, 2)
Sheet4.Cells(y, 3) = Sheet3.Cells(x, 3)
count = count + 1
y = y + 1
End If
Next x


If count = 0 Then
For y = 2 To lastrow
Sheet4.Cells(y, 1).ClearContents
Sheet4.Cells(y, 2).ClearContents
Sheet4.Cells(y, 3).ClearContents
Next y


End If
End Sub
 
Last edited by a moderator:

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi Mhmd,

Try to change the below line

Rich (BB code):
If Sheet3.Cells(x, 1) Like "*" & n & "*" Then
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,084
Messages
6,128,726
Members
449,465
Latest member
TAKLAM

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