Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 553
Default Instr() with multiple search terms

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Instr() with multiple search terms

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default 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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Instr() with multiple search terms

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
is there an equal fxn for 'InStr' in excel. Not Find or Search Clausius Excel Worksheet Functions 3 May 1st 23 03:41 AM
Two search category & two search terms avk Excel Discussion (Misc queries) 1 June 2nd 10 01:25 PM
Search returning ans in terms of Rows & Columns Will Excel Discussion (Misc queries) 10 April 5th 07 07:53 PM
searching a large database with a long list of search terms [email protected] Excel Discussion (Misc queries) 34 January 10th 06 06:23 AM
how to set up a vlookup table with 2 search terms? WendyL Excel Worksheet Functions 3 May 12th 05 01:08 PM


All times are GMT +1. The time now is 01:40 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"