+ Reply to Thread
Results 1 to 3 of 3

number to words

Hybrid View

vjn number to words 10-05-2008, 04:21 AM
dominicb Good morning vjn ...and... 10-05-2008, 04:55 AM
royUK Try this code, place it in a... 10-05-2008, 04:57 AM
  1. #1
    Registered User
    Join Date
    09-26-2008
    Location
    uae
    Posts
    1

    number to words

    D/Sir,
    Could you tell me how to change number to words (eg. 1,000.00 to one thousand) using addin

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good morning vjn

    ...and welcome to the forum!!

    Download and install my add-in from the link below.
    Once installed go to Ultimate > Formulae > Add Function and select SpellNumber from the list and click on Add Function.

    This will add a macro to your workbook that can be used as a custom functions.
    If cell A1 contains the value 1234.56 then :
    =SpellNumber(A1)
    would return :
    One Thousand Two Hundred and Thirty Four Pounds and Fifty Six Pence

    Currency is optional, but currently supported is GBP, EUR, USD and Indian Rupees.

    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Try this code, place it in a Standard Module.

    Option Explicit
     
    '****************
    ' Main Function *
    '****************
    Function SpellNumber(ByVal MyNumber)
        Dim Dollars, Cents, 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, ".")
        'Convert cents and set MyNumber to dollar amount
        If DecimalPlace > 0 Then
            Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2))
            MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
        End If
     
        Count = 1
        Do While MyNumber <> ""
           Temp = GetHundreds(Right(MyNumber, 3))
           If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
              If Len(MyNumber) > 3 Then
                 MyNumber = Left(MyNumber, Len(MyNumber) - 3)
            Else
                MyNumber = ""
            End If
            Count = Count + 1
        Loop
     
        Select Case Dollars
            Case ""
                Dollars = "No Dollars"
            Case "One"
                Dollars = "One Dollar"
            Case Else
                Dollars = Dollars & " Dollars"
        End Select
     
        Select Case Cents
            Case ""
                Cents = " and No Cents"
            Case "One"
                Cents = " and One Cent"
            Case Else
                Cents = " and " & Cents & " Cents"
        End Select
     
        SpellNumber = Dollars & Cents
    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
    You can use in a cell like this, in A1 place your number, then in B1 type = SpellNumber(A1)
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 6
    Last Post: 07-29-2008, 03:23 PM
  2. count the number of members in cells seperated by ;
    By wali in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-23-2008, 01:46 PM
  3. multyplication by finding number from rows
    By vinumv in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-14-2008, 02:22 PM
  4. ranking second number between two words
    By jamiepullen in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-17-2008, 11:06 AM
  5. Determining required number of contacts
    By Bobcalling in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-10-2007, 01:27 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1