Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format "1" as "one" in Excel, etc.

Status
Not open for further replies.

jh3016

Programmer
Jun 6, 2003
148
0
0
US
Is there a way to spell out numbers in Excel? In other words, I have numbers 1-50 listed in column A. I want to spell out "one" to "fifty" in column B.

Thanks in advance.
 
Try right-clicking the cell, Format Cells..., and choose Text from the list on the Number tab.
 
I use the following function.

It needs to be added to a module within the workbook or your personal.xls file (i it exists)

'Here is what I use, it works for up to Sextllions. It will also give you something like
'Three Hundred Thirty Dollars and Sixty Seven Cents if you pass it the optional second and third parameters. like this:

'=NumberToText(330.67,"Dollars","Cents")

' (c) Legare Coleman


Public Function NumberToText(Num As Variant, Optional vCurName As Variant, Optional vCent As Variant) As Variant
Dim TMBT As Variant
Dim sNum As String, sDec As String, sHun As String, IC As Integer
Dim Result As String, sCurName As String, sCent As String

If Application.IsNumber(Num) = False Then
NumberToText = CVErr(xlValue)
Exit Function
End If

If IsMissing(vCurName) Then
sCurName = ""
Else
sCurName = Trim(CStr(vCurName))
End If
If IsMissing(vCent) Then
sCent = ""
Else
sCent = Trim(CStr(vCent))
End If

TMBT = Array("", "Thousand", "Million", "Billion", "Trillion", "Quadrillion", "Quintillion", "Sextillion")

If IsMissing(sCent) Or IsNull(sCent) Then
sNum = Format(Application.Round(Num, 0), "0")
Else
sNum = Format(Application.Round(Num, 2), "0.00")
sDec = Right(sNum, 2)
sNum = Left(sNum, Len(sNum) - 3)
If CInt(sDec) <> 0 Then
sDec = &quot;and &quot; & Trim(HundredsToText(CVar(sDec)) & &quot; &quot; & sCent)
Else
sDec = &quot;&quot;
End If
End If

IC = 0
While Len(sNum) > 0
sHun = Right(sNum, 3)
sNum = Left(sNum, Application.Max(Len(sNum) - 3, 0))
If CInt(sHun) <> 0 Then
Result = Trim(Trim(HundredsToText(CVar(sHun)) & &quot; &quot; & TMBT(IC)) & &quot; &quot; & Result)
End If
IC = IC + 1
Wend
Result = Trim(Result & &quot; &quot; & sCurName)
Result = Trim(Result & &quot; &quot; & sDec)

NumberToText = Result

End Function

Private Function HundredsToText(Num As Integer) As String
Dim Units As Variant, Teens As Variant, Tens As Variant
Dim i As Integer, IUnit As Integer, ITen As Integer, IHundred As Integer
Dim Result As String

Units = Array(&quot;&quot;, &quot;One&quot;, &quot;Two&quot;, &quot;Three&quot;, &quot;Four&quot;, &quot;Five&quot;, &quot;Six&quot;, &quot;Seven&quot;, &quot;Eight&quot;, &quot;Nine&quot;)
Teens = Array(&quot;Ten&quot;, &quot;Eleven&quot;, &quot;Twelve&quot;, &quot;Thirteen&quot;, &quot;Fourteen&quot;, &quot;Fifteen&quot;, &quot;Sixteen&quot;, &quot;Seventeen&quot;, &quot;Eighteen&quot;, &quot;Nineteen&quot;)
Tens = Array(&quot;&quot;, &quot;&quot;, &quot;Twenty&quot;, &quot;Thirty&quot;, &quot;Fourty&quot;, &quot;Fifty&quot;, &quot;Sixty&quot;, &quot;Seventy&quot;, &quot;Eighty&quot;, &quot;Ninety&quot;)

Result = &quot;&quot;
IUnit = Num Mod 10
i = Int(Num / 10)
ITen = i Mod 10
IHundred = Int(i / 10)
If IHundred > 0 Then
Result = Units(IHundred) & &quot; Hundred&quot;
End If
If ITen = 1 Then
Result = Result & &quot; &quot; & Teens(IUnit)
Else
If ITen > 1 Then
Result = Trim(Result & &quot; &quot; & Tens(ITen) & &quot; &quot; & Units(IUnit))
Else
Result = Trim(Result & &quot; &quot; & Units(IUnit))
End If
End If

HundredsToText = Result

End Function



Kieran
 
Try

XL2000: How to Convert a Numeric Value into English Words

and:

XL: How to Convert a Numeric Value into English Words

and:

If you want an addin that provides a worksheet function that does this, download Laurent Longre's free morefunc.xll addin found here:


It is downloaded in a zip file which also contains an informative file in 'hlp' format that describes the 33 or so very useful functions included, one of which does the number to words conversion you describe (supports various
languages and currencies).


and:
(Courtesy of Andy Wiggins FCCA) of
This file might be a help:

It's in the &quot;Accountants&quot; section on page:
It contains two methods to convert numbers to words and two check writing
routines.

The code is open and commented.

And, finally:


A post containing a UDF by Bernie Deitrick that will take you into US budget territory by covering amounts into trillions.

Regards
Ken................



----------------------------------------------------------------------------
[peace] Seasons Greetings and Very Best wishes to all [2thumbsup]

----------------------------------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top