Wildcard in Instr?

M

mcl

Is it possible to use single charcater wildcards in "InStr"?
In this case I wanted to search for a "/" preceeded and followed by 2
numerical characters but it didn't work.
May I assume it can't be done or did I just use the wrong syntax?

This is what I used. I was able to search for just a "/" but when I added
the #'s it was a no go.
InStr([Remark],"##/##")
 
G

George Nicholson

Instr() doesn't support wildcards. Check out VBA's Like operator

bolResult = [Remark] Like "*##/##*"
 
M

Marshall Barton

mcl said:
Is it possible to use single charcater wildcards in "InStr"?
In this case I wanted to search for a "/" preceeded and followed by 2
numerical characters but it didn't work.
May I assume it can't be done or did I just use the wrong syntax?

This is what I used. I was able to search for just a "/" but when I added
the #'s it was a no go.
InStr([Remark],"##/##")


No wildcards with InStr, but easy enough to add it to your
code:

pos = InStr(pos+1,Remark,"/")
If pos > 0 Then
If Mid(Remark,pos-1,3) Like "##/##" Then
. . .
 

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

Top