RisingCascade
RisingCascade

Reputation: 63

How to Ignore wildcards in the range.find function

Is it possible to treat wildcards as normal chars in the range.find function.

I am searching through a list for string matches, but am running into issues, as some of the strings contain wild cards. Example:

List:
ab
cde
fghi
jk
?l

r = list.range.find(s, LookAt:=xlWhole)

if s = "??" this would result in r equalling "ab"
Where as I want "??" to be treated like a normal string that would only match a string of "??"
If s = "?l" I would want r to equal "?l" not "ab"

Upvotes: 1

Views: 2475

Answers (1)

Dante May Code
Dante May Code

Reputation: 11247

Use a ~, i.e ~?.

For your ?l, it is ~?l.

General solution:

s = Application.WorksheetFunction.Substitute(s, "?", "~?")

Upvotes: 4

Related Questions