Substring check within VBA

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

Guest

If Str1 and Str2 are strings, is there a function or simple coding within VBA
to return TRUE if Str1 is a substring of Str2, otherwise FALSE?

Thanks in advance
 
Hi Gary's Sudent,

For xl2k ==> look at the InStr function in VBA help.


BTW, Why does Gary never give you an answer?
 
Look at InStr() in VBA or even Like

if instr(1,str2,str1,vbtextcompare) > 0
or
if lcase(str2) like "*" & lcase(str1) & "*" then

I think I got my str1's and str2's correct--but you'll soon find out!

(And I made it so upper/lower case didn't matter.)
 
Thank you both very much.

Norman: Gary does give me many answers. He does not function 24/7. The
individuals that support this forum are razor-sharp and lightning-fast.

Perhaps I should change my name to Forum's Student.
 
I think InStr has been there for a long time (forever??).

I bet you were warning about instrrev???
 
You can also use

If str2 like "*" & str1 & "*" Then
....

--

HTH

RP
(remove nothere from the email address if mailing direct)
 

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