Instr() with multiple search terms
I think you should change your assignment to the 'y' variable to something
like this...
y = Abs((InStr(1, strData, "Hello", vbTextCompare) + _
InStr(1, strData, "the", vbTextCompare) + _
InStr(1, strData, "dog", vbTextCompare)) 0)
Otherwise, a value of more than 1 would be possible; and not the 2 you might
be thinking in, for example, this...
strDate = "Hello to the world"
--
Rick (MVP - Excel)
"Jacob Skaria" wrote in message
...
OR..this way
Sub ins()
Dim strData As String
strData = "Hello world"
y = InStr(1, strData, "Hello", vbTextCompare) + _
InStr(1, strData, "the", vbTextCompare) + _
InStr(1, strData, "dog", vbTextCompare)
MsgBox y
End Sub
If this post helps click Yes
---------------
Jacob Skaria
"ExcelMonkey" wrote:
I it possible to use the Instr() function with multiple search terms.
The
idea being that all below should return a value fo 1
Dim Y as Double
Y = Instr(1, "Hello World", "Hello|"The"|"Dog")
Y = Instr(1, "The World", "Hello|"The"|"Dog")
Y = Instr(1, "Dog World", "Hello|"The"|"Dog")
The idea here being to find matches at the beginning of the Target
String.
Alternatively I could use Regular Expressions. But I cannot remember how
to
use the Match functionality to return the position of the word.
Thanks
EM
|