looking for a match comparing field to value

excel 2003
access 2003
vba

is it possible to turn this code into a "Like" wildcard match ?

' This works
If CStr(rng.Offset(0, -1).Value) = rs.Fields(1) Then
 .Range("A" & j).Offset(0, 52) = "Found"
 End If

This does not work:
If CStr(rng.Offset(0, -1).Value) Like "*' &  rs.Fields(1) & '*"  Then
 .Range("A" & j).Offset(0, 52) = "FoundSomething"
 End If


Thanks
fordraiders
LVL 3
FordraidersAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Peter KwanAnalyst ProgrammerCommented:
You may use instr method

If Instr(rng.Offset(0, -1).Value, rs.Fields(1)) > 0 then ...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FordraidersAuthor Commented:
perfect Thanks
0
dlmilleCommented:
Is there a syntax error with your single quote?  Shouldn't it be:

If CStr(rng.Offset(0, -1).Value) Like "*" &  rs.Fields(1) & "*"  Then

It should work just fine with that corrected.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

dlmilleCommented:
Ok then, when you want a wildcard match, don't give up - just ensure the syntax is correct ;)

Dave
0
FordraidersAuthor Commented:
one quirk

rng.Offset(0, -1).Value =  "PROTO"

YOUR CODE will not find  "PROTO" if its at the end of the string ?
If Instr(rng.Offset(0, -1).Value, rs.Fields(1)) > 0

if the field rs.fields(1) =  "BLACKHAWK BY PROTO"

0
FordraidersAuthor Commented:
dlmile, would not work...sorry
0
dlmilleCommented:
"BLACKHAWK BY PROTO" like "*PROTO*"  works - your wildcards will work if you use the correct syntax - see my post.

Dave
0
dlmilleCommented:
fordraiders - certainly does work.  Just use the LIKE properly correctly.

Here's the proper use from Excel Help:

  Like Operator




Used to compare two strings.

Syntax

result = string Like pattern

Consult Excel Help for the GUI version of how LIKE works.

Its STRING like PATTERN, not PATTERN LIKE STRING.

Cheers,

Dave
0
FordraidersAuthor Commented:
dave,
If CStr(rng.Offset(0, -1).Value) Like "*" & rs.Fields(1) & "*" Then
  .Range("A" & j).Offset(0, 53) = "NAME MATCH"
 End If

it will not find "PROTO"  CStr(rng.Offset(0, -1).Value)    inside        "BLACKHAWK BY PROTO" "*" & rs.Fields(1) & "*"
0
dlmilleCommented:
You're doing it incorrectly.

If "PROTO" is in rng.offset(0,-1).value

and "BLACKHAWK BY PROTO" is in rs.Fields(1)

Then the correct syntax is STRING LIKE PATTERN

If rs.Fields(1) LIKE "*" & CStr(rng.Offset(0,-1).Value) & "*" Then
0
FordraidersAuthor Commented:
dave. Thanks for staying with me...ok I see what you mean now...
ok now how do you get some points ?
0
dlmilleCommented:
No need.

by the way - you might be doing the INSTR function backwards as well, since you noted it didn't work on another example, unless I missread the post - just make sure the STRING is the first parameter.

Also, suggest waiting a few :) minutes before accepting solutions especially if they come from a tangent (re: you were given a perfectly good solution, however, it didn't explain why you were having a problem with LIKE), as several Experts might be banging away competing solutions and you can have your pick, reward the first, or reward them all.

Cheers,

Dave
0
FordraidersAuthor Commented:
Thanks, again...very much ! and yes I will wait next time'
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.