# wild card search

#### Chas17

##### Well-known Member
a user enters a string in a text box on a form, presses a cmd button to start a search. the string fom the texr box is placed in
Range("SearchInput") example string 2JRCEPV0100E**VALVEX

I then run the sub below to copy all matching entries to a different range.

Sub SearchE()
NN = Range("NextTN").Value 'number of entries in first range copied from

SI = Range("SearchInput")
z = 2

For x = 1 To NN
If Cells(x, 4) = SI Then
For y = 1 To 9
Cells(z, y + 26) = Cells(x, y)
Next y
z = z + 1
End If
Next x

End Sub

Of course only exact matches copy. How would I write it so the user could use a wild card, so they could enter say 2JRCEPV0100E% (if % was the wild card)?

thanks,
Chas

### 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.

#### acw

##### MrExcel MVP
Hi

There are a couple of ways of doing this.

1) If you only put in the first part of the searchstring (say 2JRCEPV0100E) then you could do something like

If left(Cells(x, 4),1,len(SI)) = SI Then where you just match on the first number of characters.

2) Another option is to use the Find facility. This will enable you to use the wildcards. Sample code to use the find
Set c = Range("a1:a7").Find(what:="2jrcepv0100e*")
MsgBox c
Set c = Range("a1:a7").FindNext(c)
MsgBox c
Set c = Range("a1:a7").FindNext(c)

Wend
This will cycle through all the entries that match. You can then manipulate as required.

HTH

Tony

#### Chas17

##### Well-known Member
Thanks, works fine

Replies
7
Views
161
Replies
4
Views
180
Replies
9
Views
2K
Replies
8
Views
443
Replies
29
Views
565

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

1,151,883
Messages
5,766,926
Members
425,386
Latest member
DougFarley

### 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.

### Which adblocker are you using?

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

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