Finding A or B

J

Jeff Hall

Is there a syntax to Find one string or another?

eg find "Bill" or "Jean", whichever comes first
 
J

Jezebel

No. You'll have to do two searches and compare the results. You can use
regular expressions to search for one of two (or more) characters, so you
could sort of do it by searching for [BJ][ie][la][ln] but that would also
match "Jill", "Bean", "Bell", etc.
 
T

Terry

In addition to Jezebel's response....
Im not sure, but could you not use a do while loop while the results count
is <=1?

Just a thought
Terry V

Jezebel said:
No. You'll have to do two searches and compare the results. You can use
regular expressions to search for one of two (or more) characters, so you
could sort of do it by searching for [BJ][ie][la][ln] but that would also
match "Jill", "Bean", "Bell", etc.
 
H

Helmut Weber

Hi Jeff,
how about that, limited to words, of course,
and an idea more than a solution.
Sub FindTwo(Str1$, Str2$)
Dim objR As Range
Dim objW As Object
Set objR = ActiveDocument.Range
For Each objW In objR.Words
If objW.Text = Str1$ Or objW.Text = Str1$ Then
objW.Select
Exit For
End If
Next objW
End Sub
Note that a word includes the following space,
so you would have to search for "Bill " or "Jean".
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, NT 4.0
 
J

Jezebel

If you're going to try that sort of method, why not just:

a = instr(ActiveDocument.Range.Text, "Jean")
b = instr(ActiveDocument.Range.Text, "Bill")

If (a + b) > 0 then
....
 
H

Helmut Weber

Hi Jezebel,
am still lerning,
thank you for the lesson.
Greetings from Bavaria, Germany
Helmut Weber
 
J

Jezebel

Mind you, I'm not sure either of those methods is a good way to search for
text in a Word document. I've not tested it, but I think you can have
problems with UniCode if you have Option Compare Text set.
 
J

Jeff Hall

That would be quick if I always wanted to search from the top.

The actual problem is like this...

1. Where is the previous occurrence of A or B above the current selection
2. Where is the next occurrence of A or B below the current selection
Select the range between 1 and 2
 
J

Jeff Hall

Actually, this will work for me

I want to find "#TJ" or "#TW" case sensitive

so I guess the expression is "#T[JW]" matchcase=true

--------------------------------------------------------------------
Jeff Hall
--------------------------------------------------------------------
No. You'll have to do two searches and compare the results. You can use
regular expressions to search for one of two (or more) characters, so you
could sort of do it by searching for [BJ][ie][la][ln] but that would also
match "Jill", "Bean", "Bell", etc.




Jeff Hall said:
Is there a syntax to Find one string or another?

eg find "Bill" or "Jean", whichever comes first
 
J

Jeff Hall

Thanks for the suggestion. I will try it although the first document that I
want to use it on is 235 pages long!! I suspect it will be too slow.
 
J

Jezebel

Instr can work on sub-ranges of the text:

a = instr(StartPoint, ActiveDocument.Range.Text, "Jean")
 

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