Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.newusers
Ed Ed is offline
external usenet poster
 
Posts: 122
Default Help with wildcard search, please?

I'm trying to use Find (Ctrl+F) with wildcards to find a certain string
ending in a number between 60 and 81. I tried
(App A, Item No. )([60-81]{2})
but it found "App A, Item No. 10". I looked on the Word FAQ page for
Wildcards, but couldn't find how to restrict the number to "more than this
but less than that".

Can this be done with Find, or do I need to go into VBA?

Ed


  #2   Report Post  
Posted to microsoft.public.word.newusers
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default Help with wildcard search, please?

Hi Ed,

Yes, you're going to need VBA. The Find mechanism itself can't do
comparisons of the values of digits. You need something like this:

Dim myRange As Range
Dim myVal As Long

Set myRange = ActiveDocument.Range
FoundIt = False

With myRange.Find
.MatchWildcards = True
.Text = "App A, Item No. ([0-9]{2})"
.Forward = True
.Wrap = wdFindStop
Do While .Execute
myVal = Val(Right$(myRange.Text, 2))
If (60 = myVal) And (myVal = 81) Then
myRange.Select ' or do something else
Exit Do
End If
Loop
End With

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Ed wrote:
I'm trying to use Find (Ctrl+F) with wildcards to find a certain
string ending in a number between 60 and 81. I tried
(App A, Item No. )([60-81]{2})
but it found "App A, Item No. 10". I looked on the Word FAQ page for
Wildcards, but couldn't find how to restrict the number to "more than
this but less than that".

Can this be done with Find, or do I need to go into VBA?

Ed



  #3   Report Post  
Posted to microsoft.public.word.newusers
Klaus Linke Klaus Linke is offline
external usenet poster
 
Posts: 413
Default Help with wildcard search, please?

"Ed" wrote:
I'm trying to use Find (Ctrl+F) with wildcards to find a certain string
ending in a number between 60 and 81. I tried
(App A, Item No. )([60-81]{2})
but it found "App A, Item No. 10". I looked on the Word FAQ page for
Wildcards, but couldn't find how to restrict the number to "more than this
but less than that".

Can this be done with Find, or do I need to go into VBA?



Hi Ed,

Wildcards deal with patterns, and don't have any built-in concept of
numbers. You probably need VBA.

You could use a wildcard search first to find numbers between 60 and 89
([6-8][0-9]), and then you'd need to check the number (last two characters
in the selection) with VBA:

Select Case Val(Right(Selection.Text,2))
Case 60 to 81
' match
End Select

For wildcards to work in this case, you would need an "OR" operator, which
does not exist in Word wildcards:
[6][0-9] OR [7][0-9] OR [8][0-1]

Regards,
Klaus


  #4   Report Post  
Posted to microsoft.public.word.newusers
Greg Maxey Greg Maxey is offline
external usenet poster
 
Posts: 171
Default Help with wildcard search, please?

I think the closet you can get would be finding 60-89.
App A, Item No. [6-8][0-9][!0-9]

I assumed you wouldn't want to find part of:
App A, Item No. 627

Try:

Sub ScratchMacro()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "App A, Item No. [6-8][0-9][!0-9]"
.MatchWildcards = True
While .Execute
If CLng(Mid(oRng, 17, 2)) 90 Then
MsgBox oRng.Text
End If
Wend
End With
End Sub


Ed wrote:
I'm trying to use Find (Ctrl+F) with wildcards to find a certain string
ending in a number between 60 and 81. I tried
(App A, Item No. )([60-81]{2})
but it found "App A, Item No. 10". I looked on the Word FAQ page for
Wildcards, but couldn't find how to restrict the number to "more than this
but less than that".

Can this be done with Find, or do I need to go into VBA?

Ed


  #5   Report Post  
Posted to microsoft.public.word.newusers
Greg Maxey Greg Maxey is offline
external usenet poster
 
Posts: 171
Default Help with wildcard search, please?

I think the closet you can get would be finding 60-89.
App A, Item No. [6-8][0-9][!0-9]

I assumed you wouldn't want to find part of:
App A, Item No. 627

Try:

Sub ScratchMacro()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "App A, Item No. [6-8][0-9][!0-9]"
.MatchWildcards = True
While .Execute
If CLng(Mid(oRng, 17, 2)) 90 Then
MsgBox oRng.Text
End If
Wend
End With
End Sub


Ed wrote:
I'm trying to use Find (Ctrl+F) with wildcards to find a certain string
ending in a number between 60 and 81. I tried
(App A, Item No. )([60-81]{2})
but it found "App A, Item No. 10". I looked on the Word FAQ page for
Wildcards, but couldn't find how to restrict the number to "more than this
but less than that".

Can this be done with Find, or do I need to go into VBA?

Ed




  #6   Report Post  
Posted to microsoft.public.word.newusers
Ed Ed is offline
external usenet poster
 
Posts: 122
Default Help with wildcard search, please?

Huge thanks to all of you Jay, Klaus, and Greg. I really appreciate the
assistance and the codes.

Ed


  #7   Report Post  
Posted to microsoft.public.word.newusers
Greg Maxey Greg Maxey is offline
external usenet poster
 
Posts: 285
Default Help with wildcard search, please?

Jay,

Are there advantages to Val(someString) over Clng(someString)?

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

"Jay Freedman" wrote in message
...
Hi Ed,

Yes, you're going to need VBA. The Find mechanism itself can't do
comparisons of the values of digits. You need something like this:

Dim myRange As Range
Dim myVal As Long

Set myRange = ActiveDocument.Range
FoundIt = False

With myRange.Find
.MatchWildcards = True
.Text = "App A, Item No. ([0-9]{2})"
.Forward = True
.Wrap = wdFindStop
Do While .Execute
myVal = Val(Right$(myRange.Text, 2))
If (60 = myVal) And (myVal = 81) Then
myRange.Select ' or do something else
Exit Do
End If
Loop
End With

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup
so all may benefit.

Ed wrote:
I'm trying to use Find (Ctrl+F) with wildcards to find a certain
string ending in a number between 60 and 81. I tried
(App A, Item No. )([60-81]{2})
but it found "App A, Item No. 10". I looked on the Word FAQ page for
Wildcards, but couldn't find how to restrict the number to "more than
this but less than that".

Can this be done with Find, or do I need to go into VBA?

Ed





  #8   Report Post  
Posted to microsoft.public.word.newusers
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default Help with wildcard search, please?

It's mostly that Val is stuck in my memory from about 30 years of use,
and CLng is much more recent. You know the short-term memory is the
first to go. (My wife calls hers "momnesia".)

In most cases, if you assign the result of Val to a Long variable, the
result is identical to what you get from CLng, including the rounding
of non-integers, and the results will compare as equal.

There are some subtle differences, though.

- If the string contains anything other than digits and a decimal
point, Val will evaluate the start of the string up to (but not
including) the non-numeric character. It will also strip out and
ignore spaces, tabs, and line feeds. In the same situations, CLng will
throw a type mismatch error, which needs to be trapped with On Error.

This is not to say that Val is always superior. If you don't carefully
validate the input, Val can give you a number that looks reasonable
but is wrong, where CLng would clearly say "this is garbage".

- Both functions will accept arguments in hexadecimal notation. But
where CLng interprets all hex arguments as positive numbers, Val
interprets 4-digit hex numbers larger than 7FFF as negative numbers
(because the highest-order bit is considered to be a sign bit). You
won't run into this one very often!

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Thu, 27 Jul 2006 17:24:29 -0400, "Greg Maxey"
wrote:

Jay,

Are there advantages to Val(someString) over Clng(someString)?

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

"Jay Freedman" wrote in message
...
Hi Ed,

Yes, you're going to need VBA. The Find mechanism itself can't do
comparisons of the values of digits. You need something like this:

Dim myRange As Range
Dim myVal As Long

Set myRange = ActiveDocument.Range
FoundIt = False

With myRange.Find
.MatchWildcards = True
.Text = "App A, Item No. ([0-9]{2})"
.Forward = True
.Wrap = wdFindStop
Do While .Execute
myVal = Val(Right$(myRange.Text, 2))
If (60 = myVal) And (myVal = 81) Then
myRange.Select ' or do something else
Exit Do
End If
Loop
End With

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup
so all may benefit.

Ed wrote:
I'm trying to use Find (Ctrl+F) with wildcards to find a certain
string ending in a number between 60 and 81. I tried
(App A, Item No. )([60-81]{2})
but it found "App A, Item No. 10". I looked on the Word FAQ page for
Wildcards, but couldn't find how to restrict the number to "more than
this but less than that".

Can this be done with Find, or do I need to go into VBA?

Ed




  #9   Report Post  
Posted to microsoft.public.word.newusers
Greg Maxey Greg Maxey is offline
external usenet poster
 
Posts: 285
Default Help with wildcard search, please?

Thanks Jay.

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


Jay Freedman wrote:
It's mostly that Val is stuck in my memory from about 30 years of use,
and CLng is much more recent. You know the short-term memory is the
first to go. (My wife calls hers "momnesia".)

In most cases, if you assign the result of Val to a Long variable, the
result is identical to what you get from CLng, including the rounding
of non-integers, and the results will compare as equal.

There are some subtle differences, though.

- If the string contains anything other than digits and a decimal
point, Val will evaluate the start of the string up to (but not
including) the non-numeric character. It will also strip out and
ignore spaces, tabs, and line feeds. In the same situations, CLng will
throw a type mismatch error, which needs to be trapped with On Error.

This is not to say that Val is always superior. If you don't carefully
validate the input, Val can give you a number that looks reasonable
but is wrong, where CLng would clearly say "this is garbage".

- Both functions will accept arguments in hexadecimal notation. But
where CLng interprets all hex arguments as positive numbers, Val
interprets 4-digit hex numbers larger than 7FFF as negative numbers
(because the highest-order bit is considered to be a sign bit). You
won't run into this one very often!


Jay,

Are there advantages to Val(someString) over Clng(someString)?

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

"Jay Freedman" wrote in message
...
Hi Ed,

Yes, you're going to need VBA. The Find mechanism itself can't do
comparisons of the values of digits. You need something like this:

Dim myRange As Range
Dim myVal As Long

Set myRange = ActiveDocument.Range
FoundIt = False

With myRange.Find
.MatchWildcards = True
.Text = "App A, Item No. ([0-9]{2})"
.Forward = True
.Wrap = wdFindStop
Do While .Execute
myVal = Val(Right$(myRange.Text, 2))
If (60 = myVal) And (myVal = 81) Then
myRange.Select ' or do something else
Exit Do
End If
Loop
End With

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

Ed wrote:
I'm trying to use Find (Ctrl+F) with wildcards to find a certain
string ending in a number between 60 and 81. I tried
(App A, Item No. )([60-81]{2})
but it found "App A, Item No. 10". I looked on the Word FAQ page
for Wildcards, but couldn't find how to restrict the number to
"more than this but less than that".

Can this be done with Find, or do I need to go into VBA?

Ed



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
In Word - how do you clear all the search fields CyberTaz Microsoft Word Help 0 April 11th 06 07:59 PM
File Search using the asterisk (*) wildcard Kokomojo Microsoft Word Help 1 January 25th 06 05:08 AM
File Search Preview Pane ndolinger Microsoft Word Help 0 August 10th 05 09:34 PM
File Search Preview Pane ndolinger Microsoft Word Help 2 August 10th 05 04:12 PM
Problem with search feature in word 2002 Ellen Microsoft Word Help 0 February 8th 05 09:31 PM


All times are GMT +1. The time now is 07:01 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"