Thousand seperator for number

S

shbutt

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
 
M

macropod

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top