Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
As far as I remember, you would have to use an if or select case
Sub ins() If InStr(1, "Hello World", "Hello") = 1 Or _ InStr(1, "Hello World", "dog") = 1 Then y = 1 MsgBox y End Sub -- Don Guillett Microsoft MVP Excel SalesAid Software "ExcelMonkey" wrote in message ... 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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Rick; i meant to say
y = InStr(1, strData, "Hello", vbTextCompare) + _ InStr(1, strData, "the", vbTextCompare) + _ InStr(1, strData, "dog", vbTextCompare) If y 0 then 'Do something End If End Sub If this post helps click Yes --------------- Jacob Skaria "Rick Rothstein" wrote: 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
is there an equal fxn for 'InStr' in excel. Not Find or Search | Excel Worksheet Functions | |||
Two search category & two search terms | Excel Discussion (Misc queries) | |||
Search returning ans in terms of Rows & Columns | Excel Discussion (Misc queries) | |||
searching a large database with a long list of search terms | Excel Discussion (Misc queries) | |||
how to set up a vlookup table with 2 search terms? | Excel Worksheet Functions |