wild card search

Chas17

Well-known Member
Joined
Oct 16, 2002
Messages
657
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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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*")
firstaddr = c.Address
MsgBox c
Set c = Range("a1:a7").FindNext(c)
While c.Address <> firstaddr
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
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,794
Members
449,048
Latest member
greyangel23

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