Discussion Locked

Thousand Separators in numbers in Word

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I need a word macro that automatically insert comma as a thousand seperator in numbers in MS Word 2002, similar to the Comma Style in Excel.
It would be very helpful if this could be acheived as an autoformat feature, in a way that Word recognise99999999 to change it to 99,999,999

1 reply

by dklippert

It's hard to do in Word. Here's a macro that will format numbers in a table. Perhaps you can tweak it:

Sub ApplyNumberFormatToTableCol()
Dim tbl As Word.Table
Dim cel As Word.Cell
Dim NrRows As Long
Dim colCurCol As Long
Dim counter As Long
Dim sInput As String

Set tbl = Selection.Tables(1)
' The following is on one line

colCurCol = Selection.Information(wdEndOfRangeColumnNumber)
'This is one line also
NrRows = tbl.Range.Information(wdEndOfRangeRowNumber)

For counter = 1 To NrRows
Set cel = tbl.Cell(counter, colCurCol)
sInput = cel.Range.Text
sInput = Left(sInput, Len(sInput) - 2)
If IsNumeric(sInput) Then
sInput = Format(sInput, "$ 0.00") cel.Range.Text = sInput
End If
Next
End Sub

This discussion is closed to new replies.