Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Converting Numbers to Text.

Converting Numbers to Text

by Allen Wyatt
(last updated February 7, 2013)

20

There are times when you need to spell numbers out. For instance, you may want to spell out "1234" as "one thousand two hundred thirty-four." Word has no built-in function that will do the conversion for you, so you are left to create a macro that will handle the conversion.

The following macro, BigCardText, will convert any number between 0 and 999,999,999. To use it, simply place the insertion point either within the number you want to convert or just to the right of the number (if it is a single digit).

Sub BigCardText()
    Dim sDigits As String
    Dim sBigStuff As String

    sBigStuff = ""

    ' Select the full number in which the insertion point is located
    Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdMove
    Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend

    ' Store the digits in a variable
    sDigits = Trim(Selection.Text)

    If Val(sDigits) > 999999 Then
        If Val(sDigits) <= 999999999 Then
            sBigStuff = Trim(Int(Str(Val(sDigits) / 1000000)))
            ' Create a field containing the big digits and
            ' the cardtext format flag
            Selection.Fields.Add Range:=Selection.Range, _
              Type:=wdFieldEmpty, Text:="= " + sBigStuff + " \* CardText", _
              PreserveFormatting:=True

            ' Select the field and copy it
            Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
            sBigStuff = Selection.Text & " million "
            sDigits = Right(sDigits, 6)
        End If
    End If
    If Val(sDigits) <= 999999 Then
        ' Create a field containing the digits and the cardtext format flag
        Selection.Fields.Add Range:=Selection.Range, _
          Type:=wdFieldEmpty, Text:="= " + sDigits + " \* CardText", _
          PreserveFormatting:=True

        ' Select the field and copy it
        Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
        sDigits = sBigStuff & Selection.Text

        ' Now put the words in the document
        Selection.TypeText Text:=sDigits
        Selection.TypeText Text:=" "
    Else
        MsgBox "Number too large", vbOKOnly
    End If
End Sub

When using the macro, make sure that the number you are converting does not contain extraneous information, such as dollar signs or commas. When you run BigCardText, the macro checks to see if the selected number is over one million. If it is, it first works on the portion above one million, converting it to words. Then, the value below one million is converted. The final, full wording is put together and pasted back into the document, ready for use.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (203) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Converting Numbers to Text.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Totaling Across Worksheets

Want to sum the values in the same cell on a range of worksheets? It's not as easy as summing a range on the same worksheet, ...

Discover More

Maintaining the Active Cell

Move from one worksheet to another, and Excel selects whatever cell was last used in the worksheet you are selecting. If you ...

Discover More

Dragging and Dropping Pictures in a Document

Do you like to add pictures to your document just by dragging and dropping? What are you to do if it appears the capability ...

Discover More

Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!

More WordTips (menu)

Determining the Number of Fonts Available

When creating a macro, you may need to figure out how many fonts are available to Word. You can do this using the FontNames ...

Discover More

Printing the Active Document from a Macro

When you process a document in a macro, you may also want to print that document from within the same macro. Here's how to do ...

Discover More

Determining the Number of Paragraphs in a Document

When using a macro to process a document in some way, you often need to know the number of paragraphs in the document. (This ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 7 + 6?

2017-07-26 13:34:36

V.S.Rawat

currency sign and comma as a separator are standard usage all over the words.
In some cultures comma and dot are interchanged as digit separtor and Dollar - Cent separtors.

It will be a small change in your above script to make it ignore all punctuations/ characters other than digits (except for Dollar - Cent separtor) and still convert it, and convert currency sign also to words.

Hope you would some day sit out to do this small change and share the new code which will be even more versatile and stubborn and more useful to users.

Thanks.


2016-11-08 06:11:18

Ken Endacott

Paul. You have to select just the text to convert, the text must not have any non numeric words except that it can have the word 'and'. Thus if the text is 'one hundred and fifty three thousand four hundred and one dollars' you should select all except the word 'dollars'.


2016-11-07 11:22:27

Paul Naveen

Hi Endacott, if I run the macro, this is the message I'm getting. "Selection does not include a word". If I select a paragraph and run the macro, I'm getting this message. The word "" is non numeric. The word is quotes is the first word of the paragraph. Can you please provide a solution.


2016-11-04 05:27:52

Ken Endacott

Paul. See the macro in the comment below.


2016-11-03 08:44:17

Paul Naveen

I need a text to number macro. Can anybody help?


2016-04-11 08:11:13

Diwas

can you please make it to be in uppercase format on the same above formula for converting number to text in word


2016-03-10 05:09:52

Lincoln

@Touseef, I've sent you a mail on how to do it. Please check your inbox.


2016-03-09 16:28:38

touseef

Hello,
I am just wondering how to incorporate the above macro in my excel 2007 to use it? Plus when I copy it in VB it gives a syntex error.

Please help me.


2016-01-01 14:48:56

sudanec

Hi,
I build a (free) plugin if you need to convert numbers to text regularly in Word, focused on converting numbers in tables (has also some further features), feel free to use:
http://www.sudanec.com/projects/wootable/


2015-05-26 05:59:56

Lincoln

@Varalaxmi: I've indicated a SpellNumber macro above that is used in MS Word. You will have to tweak it to show "Rupees" and "Paise" instead of "Dollars" and "Cents"


2015-05-25 05:43:01

VARALAXMI

HII,I WANT TO CONVERT RUPEES IN FIGURES TO RUPEES IN WORDS IN MS WORD NOT IN EXCEL .
THANK U


2015-03-26 06:13:15

Ken Endacott

Converting in the other direction.

Here is a macro that will convert a text number such as 'one hundred million two thousand three hundred and forty-five' into 100,002,345. It will convert only whole numbers but could be modified to convert dollars and cents.

Sub TextToNumbers()
Dim NT() As Variant
Dim NB As Variant
Dim N As Long
Dim ns As String
Dim R As Range
Dim k As Long
Dim L As Long
Dim LL As Long
Dim LLL As Long
Dim s As String
Dim ss As String
Dim sss As String
Dim j As Long
Dim m As Long
Dim mm As Long
Dim mmm As Long
Dim gA() As Long
Dim gB() As Long
Dim isThousandsComma As Boolean

Dim wCount As Long
NT = Array("AND", "-", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN", _
"ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN", "NINETEEN", _
"TWENTY", "THIRTY", "FORTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY", _
"HUNDRED", "THOUSAND", "MILLION", "$%$%")
NB = Array(0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, _
11, 12, 13, 14, 15, 16, 17, 18, 19, _
20, 30, 40, 50, 60, 70, 80, 90, _
100, 1000, 1000000, 0)

isThousandsComma = True ' set to false for no commas

Set R = Selection.Range
s = R.Text
If Right(s, 1) = Chr(13) Then R.MoveEnd Unit:=wdCharacter, Count:=-1
s = R.Text
If Right(s, 1) = "." Then R.MoveEnd Unit:=wdCharacter, Count:=-1

If R.Paragraphs.Count > 1 Then
MsgBox "Selection cannot span paragraphs"
Exit Sub
End If
If Trim(R.Text) = "" Then
MsgBox "Selection does not include a word"
Exit Sub
End If

wCount = R.Words.Count
ReDim gA(wCount + 1)
ReDim gB(wCount + 1)

N = 0
ns = ""

For k = 1 To R.Words.Count
s = UCase(Trim(R.Words(k)))
If s = Chr(13) Or s = "" Then
gB(k) = 1
gA(k) = 0
GoTo FF2
End If
For m = 0 To UBound(NT) - 1
If s = NT(m) Then GoTo FF
Next m
MsgBox "The word " & """" & R.Words(k) & """" & " is non numeric"
Exit Sub
FF:
gA(k) = NB(m)
If m > UBound(NT) - 5 Then
gB(k) = 2
Else
gB(k) = 1
End If
FF2:
Next k

wCount = removeZeros(gA(), gB(), wCount)

For k = 1 To wCount - 1
If gB(k) = 1 And gB(k + 1) = 1 Then
gA(k + 1) = gA(k + 1) + gA(k)
gA(k) = 0
End If
Next k
wCount = removeZeros(gA(), gB(), wCount)

m = 1
Do
m = m + 1
Loop Until m > wCount Or gA(m) = 1000000
If m <= wCount Then ' 1000000 is at ga(m)
' check that there are no 1000s
j = 1
Do
j = j + 1
Loop Until j >= m Or gA(j) = 1000
If j < m Then
MsgBox "Cannot process thousands of millions"
Exit Sub
End If
j = 1
Do
j = j + 1
Loop Until j >= m Or gA(j) = 100
If j < m Then
gA(j) = gA(j) * gA(j - 1)
gA(j - 1) = 0
gB(j) = 1
End If
LL = 0
For j = 1 To m - 1
L = L + gA(j)
gA(j) = 0
gB(j) = 0
Next j
gA(m) = L * gA(m)
gB(m) = 1
Else
m = 0
End If ' 1000000 processed

mm = j + 1
If mm <= wCount Then
Do
mm = mm + 1
Loop Until mm > wCount Or gA(mm) = 1000
End If
If mm <= wCount Then ' 1000 is at ga(mm)
j = m + 1
Do
j = j + 1
Loop Until j >= mm Or gA(j) = 100
If j < mm Then ' have 100 preceeding 1000
gA(j) = gA(j) * gA(j - 1)
gA(j - 1) = 0
gB(j) = 1
End If
LL = 0
For j = m + 1 To mm - 1
LL = LL + gA(j)
gA(j) = 0
gB(j) = 1
Next j
gA(mm) = LL * gA(mm)
gB(mm) = 1
Else
mm = m
End If ' 1000 is at mmth entry

mmm = mm + 1
If mmm <= wCount Then
Do
mmm = mmm + 1
Loop Until mmm > wCount Or gA(mmm) = 100
End If
If mmm <= wCount Then ' 100 is at ga(mmm)
gA(mmm) = gA(mmm - 1) * gA(mmm)
gA(mmm - 1) = 0
gB(mmm) = 1
Else
mm = m
End If ' 100 is at mmmth entry

LLL = 0
For j = 1 To wCount
LLL = LLL + gA(j)
Next j

If isThousandsComma Then
s = Format(LLL, "Standard")
s = Left(s, Len(s) - 3)
Else
s = Str(LLL)
End If

R.Text = Trim(s)
R.Select
End Sub

Function removeZeros(gA() As Long, gB() As Long, ByVal wCount As Long) As Long
Dim q As Long
Dim z As Long
For q = wCount To 1 Step -1
If gA(q) = 0 Then
z = q
Do While z < wCount
gA(z) = gA(z + 1)
gB(z) = gB(z + 1)
z = z + 1
Loop
wCount = wCount - 1
End If
Next q
removeZeros = wCount
End Function


2015-03-25 13:57:38

Manuel Campos

I need Converting Numbers to Text

example: 1234 Converting one,two,three, four

thanks


2014-07-01 07:09:40

Lincoln

There is a SpellNumber function on the MS website http://support.microsoft.com/kb/213360


2014-05-26 09:39:14

awyatt

Nabil: The language used for Excel macros is VBA (Visual Basic for Applications). Other languages (such as C or C++) would not be understood by Excel.

-Allen


2014-05-25 22:51:12

Nabil

ms excel is not a compiler. But how does the code run in ms excel? am i able to run any type of c or c++ code in excel??


2013-05-08 06:53:49

Mike

Hi
I need to know how to convert 1234.57 into words eg. One Thousand Two Hundred Thirty Four And Fifty Seven Cents.... How can I do that after?

And after using mail merge, the amount of 1234.57 became 1234.567655555555322389

How can i format it to be 1,234.57?

Thanks


2013-04-30 14:20:16

Steven Seim

Additional - The request is to deal with monetary values such as:

$123,456.78

Convert to:

One Hundred Twenty Three Thousand, Four Hundred Fifty Six dollars and Seventy Eight Cents. (First letter caps)

Thanks!


2013-04-30 14:12:52

Steven Seim

Hello. This macro is spiff, but I have a question/favor to ask.

Can this be adjusted to work with punctuation?

Example: 123,456.78
123,456,789.01

Let me know please. I could use this.

Many thanks!


2012-02-28 22:12:32

Ernest Dehaan

Does this work on formulas? I ask because I tried and did not get any results.

If it does work in formuals where would it get inserted.


This Site

Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.