A Microsoft Word forum. Microsoft Office Word Forum - WordBanter

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 » Microsoft Office Word Forum - WordBanter forum » Microsoft Word Newsgroups » Microsoft Word Help
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

In Word, how can I automatically insert a comma between numbers?



 
 
Thread Tools Display Modes
  #1  
Old February 2nd 06, 05:40 PM posted to microsoft.public.word.docmanagement
external usenet poster
 
Posts: n/a
Default In Word, how can I automatically insert a comma between numbers?

When I am typing a document in Word (let's say a letter) and I type numbers
with a comma such as 1,158, I use the number pad but have to go over to the
letter pad for the comma. There should be a comma in the number pad. Is there
any way to format with auto correct with the numbers being unknown, to always
insert a comma after every number that is followed by three numbers
(1,111,111 or 1,158)? Or is there some other way that I don't know about,
such as automatically invoking a macro?
Ads
  #2  
Old February 2nd 06, 07:20 PM posted to microsoft.public.word.docmanagement
external usenet poster
 
Posts: n/a
Default In Word, how can I automatically insert a comma between numbers?

ALT + 044 should give you a comma.
--
Carol A. Bratt, MCP



"sharris" wrote:

When I am typing a document in Word (let's say a letter) and I type numbers
with a comma such as 1,158, I use the number pad but have to go over to the
letter pad for the comma. There should be a comma in the number pad. Is there
any way to format with auto correct with the numbers being unknown, to always
insert a comma after every number that is followed by three numbers
(1,111,111 or 1,158)? Or is there some other way that I don't know about,
such as automatically invoking a macro?

  #3  
Old February 4th 06, 12:46 AM posted to microsoft.public.word.docmanagement
external usenet poster
 
Posts: n/a
Default In Word, how can I automatically insert a comma between numbers?

I suspect there is a Find/Replace that would be more direct but this macro
should do what you are asking.

_ __ ______ __________________________

Sub AddCommasToNumbers()

Dim rngOriginal As Range
Dim strTemp As String

Application.ScreenUpdating = False

Set rngOriginal = Selection.Range

ActiveDocument.Range(0, 0).Select

With Selection.Find
.ClearFormatting
.Text = "[0-9]{4,}"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True

Do While .Execute
strTemp = Selection.Text
Selection.Text = Format$(strTemp, "#,##0")
Selection.Collapse wdCollapseEnd
Loop
End With

rngOriginal.Select

Application.ScreenUpdating = True

End Sub

______________________________________________

Steve Yandl


"sharris" wrote in message
...
When I am typing a document in Word (let's say a letter) and I type
numbers
with a comma such as 1,158, I use the number pad but have to go over to
the
letter pad for the comma. There should be a comma in the number pad. Is
there
any way to format with auto correct with the numbers being unknown, to
always
insert a comma after every number that is followed by three numbers
(1,111,111 or 1,158)? Or is there some other way that I don't know about,
such as automatically invoking a macro?



  #4  
Old February 4th 06, 01:51 AM posted to microsoft.public.word.docmanagement
external usenet poster
 
Posts: n/a
Default In Word, how can I automatically insert a comma between numbers?

Steve,

Expanded your suggestion a bit as I wouldn't expect you would want to format
numbers like phone numbers 1-800-867-5309, SSN's 123-45-6789, or Serial
Numbers
123SEWR3432432143SWQ21, etc.

Sub CommaFormatNumbers()

Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "([0-9]{4,})"
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
While .Execute
Select Case Asc(oRng.Characters.Last.Next)
Case 7, 9, 10, 11, 13, 32
On Error GoTo Handler
Select Case Asc(oRng.Characters.First.Previous)
Case 7, 9, 10, 11, 13, 32
Proceed:
oRng = Format$(oRng, "#,##0")
oRng.Collapse wdCollapseEnd
Case Else
oRng.Collapse wdCollapseEnd
End Select
Case Else
'Do Nothing
End Select
Wend
End With
Exit Sub
Handler:
Resume Proceed
End Sub


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


Steve Yandl wrote:
I suspect there is a Find/Replace that would be more direct but this
macro should do what you are asking.

_ __ ______ __________________________

Sub AddCommasToNumbers()

Dim rngOriginal As Range
Dim strTemp As String

Application.ScreenUpdating = False

Set rngOriginal = Selection.Range

ActiveDocument.Range(0, 0).Select

With Selection.Find
.ClearFormatting
.Text = "[0-9]{4,}"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True

Do While .Execute
strTemp = Selection.Text
Selection.Text = Format$(strTemp, "#,##0")
Selection.Collapse wdCollapseEnd
Loop
End With

rngOriginal.Select

Application.ScreenUpdating = True

End Sub

______________________________________________

Steve Yandl


"sharris" wrote in message
...
When I am typing a document in Word (let's say a letter) and I type
numbers
with a comma such as 1,158, I use the number pad but have to go over
to the
letter pad for the comma. There should be a comma in the number pad.
Is there
any way to format with auto correct with the numbers being unknown,
to always
insert a comma after every number that is followed by three numbers
(1,111,111 or 1,158)? Or is there some other way that I don't know
about, such as automatically invoking a macro?



  #5  
Old February 4th 06, 04:32 AM posted to microsoft.public.word.docmanagement
external usenet poster
 
Posts: n/a
Default In Word, how can I automatically insert a comma between numbers?

Greg,

You're assuming the original poster isn't an eccentric who would like commas
in those text/number strings.vbg. Thanks for the improved code. To be
honest, I only do "10 key" entries in Excel where I can easily modify number
format; in Word, I've never found it a problem to type a comma in the few
cases where I enter large numbers. I was mostly interested in the question
to see if there was a slick 'Find/Replace' that could do the deed without a
subroutine.

Steve



"Greg Maxey" wrote in message
...
Steve,

Expanded your suggestion a bit as I wouldn't expect you would want to
format numbers like phone numbers 1-800-867-5309, SSN's 123-45-6789, or
Serial Numbers
123SEWR3432432143SWQ21, etc.

Sub CommaFormatNumbers()

Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "([0-9]{4,})"
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
While .Execute
Select Case Asc(oRng.Characters.Last.Next)
Case 7, 9, 10, 11, 13, 32
On Error GoTo Handler
Select Case Asc(oRng.Characters.First.Previous)
Case 7, 9, 10, 11, 13, 32
Proceed:
oRng = Format$(oRng, "#,##0")
oRng.Collapse wdCollapseEnd
Case Else
oRng.Collapse wdCollapseEnd
End Select
Case Else
'Do Nothing
End Select
Wend
End With
Exit Sub
Handler:
Resume Proceed
End Sub


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


Steve Yandl wrote:
I suspect there is a Find/Replace that would be more direct but this
macro should do what you are asking.

_ __ ______ __________________________

Sub AddCommasToNumbers()

Dim rngOriginal As Range
Dim strTemp As String

Application.ScreenUpdating = False

Set rngOriginal = Selection.Range

ActiveDocument.Range(0, 0).Select

With Selection.Find
.ClearFormatting
.Text = "[0-9]{4,}"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True

Do While .Execute
strTemp = Selection.Text
Selection.Text = Format$(strTemp, "#,##0")
Selection.Collapse wdCollapseEnd
Loop
End With

rngOriginal.Select

Application.ScreenUpdating = True

End Sub

______________________________________________

Steve Yandl


"sharris" wrote in message
...
When I am typing a document in Word (let's say a letter) and I type
numbers
with a comma such as 1,158, I use the number pad but have to go over
to the
letter pad for the comma. There should be a comma in the number pad.
Is there
any way to format with auto correct with the numbers being unknown,
to always
insert a comma after every number that is followed by three numbers
(1,111,111 or 1,158)? Or is there some other way that I don't know
about, such as automatically invoking a macro?





 




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 On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
In Word, how do I surpress headers and footers on page 2 Bill Microsoft Word Help 1 December 15th 05 06:13 PM
Word 97 in Windows XP to maintain formatting Charlie''s Word VBA questions Microsoft Word Help 21 October 24th 05 09:49 PM
chapter & page number @ bottom of page Grace Page Layout 9 October 12th 05 06:38 AM
Macros - Keyboard Commands Janet Microsoft Word Help 6 April 11th 05 05:28 AM
How do I create & merge specific data base & master documents? maggiev New Users 2 January 12th 05 11:30 PM


All times are GMT +1. The time now is 09:18 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 2004-2014 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.