turning number into text
You can copy the code below into a codemodule, and use a formula like
=SpellNumber2(A2)
=SpellNumber2(4)
If you numbers are all less than 1000, you can use
=MakeWord(A2)
=MakeWord(4)
There are also version that will do currency strings (Four Dollars and 51/100, etc.)
HTH,
Bernie
MS Excel MVP
Function SpellNumber2(ByVal n As Double) As String
Dim myLength As Long
Dim i As Long
Dim myNum As Long
Dim Remainder As Long
SpellNumber2 = ""
Remainder = Round(100 * (n - Int(n)), 0)
myLength = Int(Application.Log10(n) / 3)
For i = myLength To 0 Step -1
myNum = Int(n / 10 ^ (i * 3))
n = n - myNum * 10 ^ (i * 3)
If myNum 0 Then
SpellNumber2 = SpellNumber2 & MakeWord(Int(myNum)) & _
Choose(i + 1, "", " thousand ", " million ", " billion ", " trillion ")
End If
Next i
SpellNumber2 = Application.Trim(SpellNumber2)
End Function
Function MakeWord(ByVal inValue As Long) As String
Dim unitWord, tenWord
Dim n As Long
Dim unit As Long, ten As Long, hund As Long
unitWord = Array("", "one", "two", "three", "four", _
"five", "six", "seven", "eight", _
"nine", "ten", "eleven", "twelve", _
"thirteen", "fourteen", "fifteen", _
"sixteen", "seventeen", "eighteen", "nineteen")
tenWord = Array("", "ten", "twenty", "thirty", "forty", _
"fifty", "sixty", "seventy", "eighty", "ninety")
MakeWord = ""
n = inValue
If n = 0 Then MakeWord = "zero"
hund = n \ 100
If hund 0 Then MakeWord = MakeWord & MakeWord(Int(hund)) & " hundred "
n = n - hund * 100
If n < 20 Then
ten = n
MakeWord = MakeWord & unitWord(ten) & " "
Else
ten = n \ 10
MakeWord = MakeWord & tenWord(ten) & " "
unit = n - ten * 10
MakeWord = Trim(MakeWord & unitWord(unit))
End If
MakeWord = Application.Proper(Trim(MakeWord))
End Function
"Melissa" wrote in message
...
Does anyone have a formula to turn a number into text. For example
2 = two
3 = three
4 = four
5 = five
Thanks!
|