Finding numbers with or without commas

  • Thread starter Thread starter Larry
  • Start date Start date
L

Larry

Using Word's Search and Replace function, how would I find all numbers in a
document, whether they are separated into columns by commas or not?

Such as 5 or 100 or 1,100 or 2,300,000

I've tried everything I could think of, using the [ ] and {1,} syntax and
can't get it.

I'm working with Word 97.

Thanks

Larry
 
Hi Larry,

You could use:
<[0-9,.]{1,}>
with the 'use wildcards' option checked. This will find decimals too.

Note that, because Find/Replace treats the commas as word delimiters, executing the above Find expression on, say, 10,000.01 will
first find 10,000.01, then 000.01 and, finally, 01
 
You could use:
<[0-9,.]{1,}>
with the 'use wildcards' option checked. This will find decimals too.

Macropod,

Thanks.

It finds all the numbers except for 2,300,000.

Odd. If it finds 1,100 why doesn't it find 2,300,000?

Also, I don't need to find decimals with this search. I'm only dealing with
round numbers.

Another oddity: it opened the footer of the document and found the page
number in there.

Larry
 
Hi Larry,

The problem was that the Find expression disallows numbers followed by a period.

Try using:
<[0-9,.]{1,}
instead.

--
Cheers
macropod
[Microsoft MVP - Word]


Larry said:
You could use:
<[0-9,.]{1,}>
with the 'use wildcards' option checked. This will find decimals too.

Macropod,

Thanks.

It finds all the numbers except for 2,300,000.

Odd. If it finds 1,100 why doesn't it find 2,300,000?

Also, I don't need to find decimals with this search. I'm only dealing with
round numbers.

Another oddity: it opened the footer of the document and found the page
number in there.

Larry
 
I didn't mention before, I'm looking for numbers preceded by the British
symbol for pounds, like

£3,500

I kept playing with it and got something which is almost there but not
quite.

This code

^0163([0-9,]{1,})

works, with one exception. If the number is followed by a comma, the Search
finds the comma as well. This seems unavoidable, given that I'm looking for
commas inside the number. How then can I keep it from finding a comma after
the number? I've tried a bunch of things, can't get it to find the number
while not finding the comma following the number.
 
In this case you are going to have to use a macro to eliminate the unwanted
extra characters. The following will find only the numbers and the pound
sign (that can be eliminated from the found string also by removing the
quote from the start of the indicated line.). You haven't said what you want
to do with the found strings, so the macro merely displays them in message
boxes:

Sub FindCashAmounts()
Dim oRng As Range
With Selection
.HomeKey wdStory
With .Find
While .Execute(findText:="£[0-9,.]{1,}", MatchWildcards:=True)
Set oRng = Selection.Range
Select Case oRng.Characters.Last
Case Is = ",", "."
oRng.End = oRng.End - 1
Case Else
End Select
'Next line removes the £ sign from the found string
'If oRng.Characters.First = "£" Then _
oRng.Start = oRng.Start + 1
'do what you want with the found text here e.g.
MsgBox oRng
Wend
End With
End With
End Sub

http://www.gmayor.com/installing_macro.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
I think what I want is not possible with a simple search. I think I'm going
to have to create a macro which stops after each find and retracts the
selection from the comma if there is one.
 
I guess our messages crossed in transit?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
I guess our messages crossed in transit?

Yes, we had the same thought. Thanks for the code.

Larry
 
Back
Top