DOLLAR SIGN TO A COLUMN

C

Carolan

I made a table in Word. Is there a way to make a column that will
automatically add the dollar sign ($) when I type in it???
 
M

macropod

Hi Carolan,

Word tables don't support automatic number formatting - you either have to
add the '$' manually or have it generated as part of a formfield or formula
field (neither of which you'd want to use for straight data-entry.

Cheers
 
H

Helmut Weber

Hi Carolan,

a bit of programming just for fun,
nothing serious really,
but if you like it, you might want to learn more about VBA.

Example for column 1:

Sub NextCell()
Dim n As String
If Selection.Information(wdEndOfRangeColumnNumber) = 1 Then
n = Selection.Cells(1).Range.Text
n = Left(n, Len(n) - 2)
If IsNumeric(Left(n, Len(n))) And _
Right(n, 2) <> " $" Then
n = n & " $"
Selection.Cells(1).Range.Text = n
End If
End If
WordBasic.NextCell
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
H

Helmut Weber

Hi Carolan,
May seem silly on my part - but how do I make this work work??

That's the real difficult part for a beginner,
hardly possible to take you by the hand with so many possibilities.

Just one of several ways:

Open the VBA-editor [alt F11],
open the project explorer [ctrl r],
which may be open anyway,
click on "normal" usually on top and bold
in the "project - project" window,
in the menu, click on "insert, module".

Paste this:
'---
Sub NextCell()
' revised !
Dim n As String
If Selection.Information(wdEndOfRangeColumnNumber) = 1 Then
n = Selection.Cells(1).Range.Text
n = Left(n, Len(n) - 2)
If IsNumeric(n) And _
Right(n, 2) <> " $" Then
n = n & " $"
Selection.Cells(1).Range.Text = n
End If
End If
WordBasic.NextCell
End Sub
'---

Save: [ctrl s]
Close: [alt F4]

If You press [tab] in a cell,
the built in command "NextCell" is executed.
However, since you have your own command "NextCell" now,
your "NextCell" is executed.
It overrides the built in command.

But, as with the new "NextCell"
the selection wouldn't move anymore,
it is necessary to have a substitute,
which is WordBasic.NextCell, a usefule relict from former times.

The macro grabs the text in the cell,
cuts off the cell mark, which is two characters long,
checks whether what's left is a number,
checks whether the rightmost 2 characters are not " $" anyway,
and if so, set the cells text to the number & " $".


HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
C

Carolan

Thanks so very much, Helmut - I even managed to change to column it effects.
It's a wonderful tool.
--
Carolan
Alberta, Canada


Helmut Weber said:
Hi Carolan,
May seem silly on my part - but how do I make this work work??

That's the real difficult part for a beginner,
hardly possible to take you by the hand with so many possibilities.

Just one of several ways:

Open the VBA-editor [alt F11],
open the project explorer [ctrl r],
which may be open anyway,
click on "normal" usually on top and bold
in the "project - project" window,
in the menu, click on "insert, module".

Paste this:
'---
Sub NextCell()
' revised !
Dim n As String
If Selection.Information(wdEndOfRangeColumnNumber) = 1 Then
n = Selection.Cells(1).Range.Text
n = Left(n, Len(n) - 2)
If IsNumeric(n) And _
Right(n, 2) <> " $" Then
n = n & " $"
Selection.Cells(1).Range.Text = n
End If
End If
WordBasic.NextCell
End Sub
'---

Save: [ctrl s]
Close: [alt F4]

If You press [tab] in a cell,
the built in command "NextCell" is executed.
However, since you have your own command "NextCell" now,
your "NextCell" is executed.
It overrides the built in command.

But, as with the new "NextCell"
the selection wouldn't move anymore,
it is necessary to have a substitute,
which is WordBasic.NextCell, a usefule relict from former times.

The macro grabs the text in the cell,
cuts off the cell mark, which is two characters long,
checks whether what's left is a number,
checks whether the rightmost 2 characters are not " $" anyway,
and if so, set the cells text to the number & " $".


HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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