how to use * wildcard in .find

User avatar
stuck
Panoramic Lounger
Posts: 8163
Joined: 25 Jan 2010, 09:09
Location: retirement

how to use * wildcard in .find

Post by stuck »

I'd like to tweak an exact match .find:

Code: Select all

Set rngFound = Range("A2:AAA2").Find(myVariable)
to work with an asterisk wild card. A search suggested all I needed was:

Code: Select all

Set rngFound = Range("A2:AAA2").Find(what:=myVariable*)
but that gives 'syntax error'

What is the correct syntax?

Thanks,

Ken

User avatar
HansV
Administrator
Posts: 78416
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: how to use * wildcard in .find

Post by HansV »

Use

What:=myVariable&"*"
Best wishes,
Hans

User avatar
stuck
Panoramic Lounger
Posts: 8163
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: how to use * wildcard in .find

Post by stuck »

That worked after I added spaces:

Code: Select all

What:=myVariable & "*"
:thankyou:

Ken
PS my POP solution was to add a line after myVariable was first set:

Code: Select all

myVariable = myVariable & "*"