Find string within a text in VBA

N

neta

HI,

How can I find a specific string in a text within a VBA code. Fo
example - to search "Japan" in "the capital of Japan is Tokyo" an
receive "TRUE" if found and "FALSE" if not..

Thanks
 
J

JE McGimpsey

One way:

Dim bFound As Boolean
bFound = InStr("the capital of Japan is Tokyo","Japan") > 0
 
F

Frank Kabel

Hi
use InStr for this. e.g.
If InStr(range("A1").value,"Japan")>0 then
msgbox "Found it"
end if
 
N

Norman Harker

Hi Neta!

One way:

=NOT(ISERROR(FIND(" Japan ",A1)))

Note that I've put a space either end of the word sought so as to
avoid TRUE for Japanese.

If you have a series of similar requests you could use:

Put the Country in F1 and then use:

=NOT(ISERROR(FIND(" "&F1&" ",A1)))
 
J

Jack Sons

Norman,

Thanks, could never have guessed.
Now, don't get mad at me, what the heck is "Strine expression"?

Jack.
 

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