number to text

vpecenik

New Member
Joined
Dec 23, 2004
Messages
2
:rolleyes: How I can convert number to text. For example: 126 to "one hundred twenty six"?
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
(y) How I can customize spelled out text and algorithm. My language is not present in arguments. Is any macro to do it? Very thanks, and Marry Christmas.
 
Upvote 0
If it helps, here is a function that I found, which I modified a bit.

Code:
Option Explicit

'****************
' Main Function *
'****************
Function SpellNumber(ByVal MyNumber)
    Dim WholeNum, Temp
    Dim DecimalPlace, Count

    ReDim Place(9) As String
    Place(2) = " thousand "
    Place(3) = " million "
    Place(4) = " billion "
    Place(5) = " trillion "

    ' String representation of amount
    MyNumber = Trim(Str(MyNumber))

    ' Position of decimal place 0 if none
    DecimalPlace = InStr(MyNumber, ".")
    'Set MyNumber
    If DecimalPlace > 0 Then
        MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
    End If

    Count = 1
    Do While MyNumber <> ""
       Temp = GetHundreds(Right(MyNumber, 3))
       If Temp <> "" Then WholeNum = Temp & Place(Count) & WholeNum
          If Len(MyNumber) > 3 Then
             MyNumber = Left(MyNumber, Len(MyNumber) - 3)
        Else
            MyNumber = ""
        End If
        Count = Count + 1
    Loop

    SpellNumber = WholeNum
End Function

'*******************************************
' Converts a number from 100-999 into text *
'*******************************************
Function GetHundreds(ByVal MyNumber)
    Dim Result As String

    If Val(MyNumber) = 0 Then Exit Function
    MyNumber = Right("000" & MyNumber, 3)

    'Convert the hundreds place
    If Mid(MyNumber, 1, 1) <> "0" Then
        Result = GetDigit(Mid(MyNumber, 1, 1)) & " hundred "
    End If

    'Convert the tens and ones place
    If Mid(MyNumber, 2, 1) <> "0" Then
        Result = Result & GetTens(Mid(MyNumber, 2))
    Else
        Result = Result & GetDigit(Mid(MyNumber, 3))
    End If

    GetHundreds = Result
End Function

'*********************************************
' Converts a number from 10 to 99 into text. *
'*********************************************
Function GetTens(TensText)
    Dim Result As String

    Result = ""           'null out the temporary function value
    If Val(Left(TensText, 1)) = 1 Then   ' If value between 10-19
        Select Case Val(TensText)
            Case 10: Result = "ten"
            Case 11: Result = "eleven"
            Case 12: Result = "twelve"
            Case 13: Result = "thirteen"
            Case 14: Result = "fourteen"
            Case 15: Result = "fifteen"
            Case 16: Result = "sixteen"
            Case 17: Result = "seventeen"
            Case 18: Result = "eighteen"
            Case 19: Result = "nineteen"
            Case Else
        End Select
      Else                                 ' If value between 20-99
        Select Case Val(Left(TensText, 1))
            Case 2: Result = "twenty "
            Case 3: Result = "thirty "
            Case 4: Result = "forty "
            Case 5: Result = "fifty "
            Case 6: Result = "sixty "
            Case 7: Result = "seventy "
            Case 8: Result = "eighty "
            Case 9: Result = "ninety "
            Case Else
        End Select
         Result = Result & GetDigit _
            (Right(TensText, 1))  'Retrieve ones place
      End If
      GetTens = Result
   End Function

'*******************************************
' Converts a number from 1 to 9 into text. *
'*******************************************
Function GetDigit(Digit)
    Select Case Val(Digit)
        Case 1: GetDigit = "one"
        Case 2: GetDigit = "two"
        Case 3: GetDigit = "three"
        Case 4: GetDigit = "four"
        Case 5: GetDigit = "five"
        Case 6: GetDigit = "six"
        Case 7: GetDigit = "seven"
        Case 8: GetDigit = "eight"
        Case 9: GetDigit = "nine"
        Case Else: GetDigit = ""
    End Select
End Function
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,739
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top