Boolean Find

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

Hello,

I think I've seen a post here explaining a way to use the Find Method in VBA
to effectively return "True" or "False". I have a variable string that I
want to search for a particular sub-string. If it contains Sub-String A, I
perform Action A, if it is Sub-String B, I perform Action B, and if it is
neither, I perform Action C.

Any suggestions?

Bill
 
Do you mean in a formula?

=IF(ISNUMBER(FIND("substringA","string")),"Action
A",IF(ISNUMBER(FIND("substringB","string")),"Action B","Action C"))

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Sorry, no, I meant in a macro.

Anyway, I used "Like" as follows:

Dim mysearchresult as Boolean
mysearchresult = False
mysearchresult = mySubjectText Like mySearchTextA
If mysearchresult then
Action A
Else
mysearchresult = mySubjectText Like mySearchTextB
If mysearchresult then
Action B
Else
Action C
End if
End if

Note that I have a variable, mySearchTextA. You specify the search text
explicitly using double-quotes. In any case, you can use typical
wildcareds, such as an asterisk for "any number of any character".

Thanks for the reply.
 

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