View Single Post
  #2   Report Post  
Posted to microsoft.public.word.formatting.longdocs
macropod[_2_] macropod[_2_] is offline
external usenet poster
 
Posts: 2,059
Default Thousand seperator for number

Hi shbutt,

There's no auto-formatting for numbers in Word, but the following macro will format any selected table cells containing only
unformatted numbers:

Sub NumberFormat()
Dim oCel As Cell, RngCel As Range
With Selection
If .Information(wdWithInTable) = True Then
For Each oCel In .Cells
Set RngCel = oCel.Range
RngCel.MoveEnd Unit:=wdCharacter, Count:=-1
If IsNumeric(RngCel.Text) Then
If InStr(RngCel.Text, ",") = 0 Then
If InStr(RngCel.Text, ".") = 0 Then
RngCel.Text = Format(RngCel.Text, "#,##0")
Else
RngCel.Text = Format(RngCel.Text, "#,##0.00")
End If
End If
End If
Next
Set RngCel = Nothing
End If
End With
End Sub

As coded, numbers:
.. without decimal places will be given thousands separators; and
.. with decimal places will be given thousands separators and rounded to 2 decimal places.

--
Cheers
macropod
[Microsoft MVP - Word]


"shbutt" wrote in message ...
I work with huge numbers in tables a lot and need to use thousand seperator
formatting on these numbers. What should I do to automatically apply desired
formatting on selected numbers. Is there any default setting in word for this
or any vba macro?

I am using Word 2007 on Win XP.

Regards,

Shahbaz