Wild Card for partial matches.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a column with multiple numbers in them,
example of one cell 0502,0399

I want to be able to find partial matches like just the 0502. right now I
have this..

For Each c In MyRange
If c = "*0502*" Then
MsgBox "yes"
End If
Next c

I'm trying to use the * as a wild card but its looking it up as if I want to
find the * as well as the numbers. Any Ideas?
 
In regular Excel, the Edit/Find command accepts ? and * as wildcards by
default.

In VBA, look up the LIKE operator.
 
Other possibilities:

- Use Application.WorksheetFunction to use the FIND or SEARCH function

- Use the Find/FindNext/Findprevious method of the Range object

- Use the VBA built-in function Instr
 
sub FindData()
Set rng = Selection.Find(What:="0502", _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
End Sub

the LookAt:=xlPart lets if find the substring.

If you want to find all instances, try applying an autofilter using custom
and select Contains and specify 0502 of look in Excel VBA help at the
FindNext method sample code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top