A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Finding numbers with or without commas



 
 
Thread Tools Display Modes
  #1  
Old September 11th, 2009, 06:58 PM posted to microsoft.public.word.newusers
Larry
external usenet poster
 
Posts: 151
Default Finding numbers with or without commas

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

  #2  
Old September 11th, 2009, 11:06 PM posted to microsoft.public.word.newusers
macropod[_2_]
external usenet poster
 
Posts: 2,402
Default Finding numbers with or without commas

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

--
Cheers
macropod
[Microsoft MVP - Word]


"Larry" wrote in message ...
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


  #3  
Old September 12th, 2009, 02:34 PM posted to microsoft.public.word.newusers
Larry
external usenet poster
 
Posts: 151
Default Finding numbers with or without commas

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

  #4  
Old September 13th, 2009, 11:06 PM posted to microsoft.public.word.newusers
macropod[_2_]
external usenet poster
 
Posts: 2,402
Default Finding numbers with or without commas

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" wrote in message ...
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

  #5  
Old September 14th, 2009, 06:09 AM posted to microsoft.public.word.newusers
Larry
external usenet poster
 
Posts: 151
Default Finding numbers with or without commas

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.

  #6  
Old September 14th, 2009, 06:54 AM posted to microsoft.public.word.newusers
Graham Mayor
external usenet poster
 
Posts: 18,297
Default Finding numbers with or without commas

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
Word MVP web site http://word.mvps.org



Larry wrote:
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.



  #7  
Old September 14th, 2009, 07:14 AM posted to microsoft.public.word.newusers
Larry
external usenet poster
 
Posts: 151
Default Finding numbers with or without commas

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.

  #8  
Old September 14th, 2009, 07:17 AM posted to microsoft.public.word.newusers
Graham Mayor
external usenet poster
 
Posts: 18,297
Default Finding numbers with or without commas

I guess our messages crossed in transit?

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org


Larry wrote:
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.



  #9  
Old September 14th, 2009, 08:27 PM posted to microsoft.public.word.newusers
Larry
external usenet poster
 
Posts: 151
Default Finding numbers with or without commas

I guess our messages crossed in transit?

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

Larry

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:13 PM.


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