How to make numbers look like currency in Word using a style?

N

n_deneane93

I want to be able to enter numbers in to a column of a table and have it
automatically change to look like a currency value (2500 becomes $2,500.00)
-- like it does in Excel. Is this possible in Word with a style or a macro?
 
S

Suzanne S. Barnhill

There's no way to do this in Word unless (a) you insert an Excel sheet or
(b) the number is a field of some sort. In the latter case, you can use a
numeric picture switch to format it.



n_deneane93 said:
I want to be able to enter numbers in to a column of a table and have it
automatically change to look like a currency value (2500 becomes $2,500.00)
-- like it does in Excel. Is this possible in Word with a style or a
macro?
 
D

Doug Robbins - Word MVP

Starting with the second row, the following macro will convert all numbers
in the second column of the first table in the document.

Dim i As Long, mynum As Range
With ActiveDocument.Tables(1)
For i = 2 To .Rows.Count
Set mynum = .Cell(i, 2).Range
mynum.End = mynum.End - 1
.Cell(i, 2).Range = Format(mynum, "$#,##0.00")
Next i
End With

To have it operate on the first row, change i = 2 to i = 1; for a different
column change Cell(i, 2) to Cell(i, n) where n is the number of the column
and for a different table, change Tables(1) to Tables(#) where # is the
number of the table in the document.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
N

n_deneane93

Thanks! I think I understand and I might be able to do that. I knew it
would not be as easy as Excel and figured some sort of macro would have to do
the trick. I'll work on it a bit and see what happens! Thanks for the tip.
 
N

n_deneane93

Thanks! I don't get it, but I am sure it works. My knowledge of macros is
nil. I guessed it would take a macro of some sort to make it work, but this
appears to be way out of my league. Thanks for taking the time to post.
You've answered my question.
 
G

Greg

Is this possible in Word with a style or a macro?

Actually it is possible with a macro:

Sub ConvertToCurrencyAndAdvance()
Dim i As Long
Dim j As Long
Dim oNum As Range
If Not Selection.Information(wdWithInTable) Then Exit Sub
i = Selection.Information(wdStartOfRangeRowNumber)
j = Selection.Information(wdStartOfRangeColumnNumber)
With Selection.Tables(1)
Set oNum = .Cell(i, j).Range
oNum.End = oNum.End - 1
If IsNumeric(oNum) Then
.Cell(i, j).Range = Format(oNum, "$#,##0.00")
If i < .Rows.Count Then
.Cell(i + 1, j).Select
ElseIf j < .Columns.Count Then
.Cell(2, j + 1).Select
Else
.Cell(2, 1).Select
End If
Selection.Collapse Direction:=wdCollapseStart
Else
Beep
oNum.Select
End If
End With
End Sub

You will need to assign to an easy keyboard shortcut. Maybe ALT+Enter
or something similar. The macro will current valid numeric entries in
the cell and move down 1 cell. When it reaches the end of the cell it
will advance to the second row of the next column (or first column if
already in last column). You could easily adapt the code to advance
across vice down or to start in the first vice second row.

HTH
 

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