Closed Thread
Results 1 to 2 of 2

Convert Digits to Words in excel

  1. #1
    Forum Contributor
    Join Date
    07-21-2009
    Location
    Kuwait
    MS-Off Ver
    Excel 2019
    Posts
    292

    Thumbs up Convert Digits to Words in excel

    Hi all,

    I m doing a urgent work and I have a probelm and it drove me a lot of..i tried my best but i could not add a word " US Dollar" in this function (As below) as by this script i can convert 10 to ten..but i want exactly "US Dollar Ten"

    So any one can add "US DOllar" alongwith 'Ten" if i type 10 in exell..

    I wil apprecite for any help

    Code

    PHP Code: 
    Function English(ByVal N As Currency) As String 
                
    Const Thousand 1000
                Const 
    Million Thousand Thousand 
                
    Const Billion Thousand Million 
                
    Const Trillion Thousand Billion 
                
    If (0@) Then English "zero": Exit Function 
                
    Dim Buf As String: If (0@) Then Buf "negative " Else Buf "" 
                
    Dim Frac As CurrencyFrac Abs(Fix(N)) 
                If (
    0@ Or Frac <> 0@) Then N Abs(Fix(N)) 
                
    Dim AtLeastOne As IntegerAtLeastOne >= 
                
    If (>= TrillionThen 
                    Debug
    .Print 
                    Buf 
    Buf EnglishDigitGroup(Int(Trillion)) & " trillion" 
                    
    Int(Trillion) * Trillion 
                    
    If (>= 1@) Then Buf Buf " " 
                
    End If 
                If (
    >= BillionThen 
                    Debug
    .Print 
                    Buf 
    Buf EnglishDigitGroup(Int(Billion)) & " billion" 
                    
    Int(Billion) * Billion 
                    
    If (>= 1@) Then Buf Buf " " 
                
    End If 
                If (
    >= MillionThen 
                    Debug
    .Print 
                    Buf 
    Buf EnglishDigitGroup(N  Million) & " million" 
                    
    N Mod Million 
                    
    If (>= 1@) Then Buf Buf " " 
                
    End If 
                If (
    >= ThousandThen 
                    Debug
    .Print 
                    Buf 
    Buf EnglishDigitGroup(N  Thousand) & " thousand" 
                    
    N Mod Thousand 
                    
    If (>= 1@) Then Buf Buf " " 
                
    End If 
                If (
    >= 1@) Then 
                    Debug
    .Print 
                    Buf 
    Buf EnglishDigitGroup(N
                
    End If 
                If (
    Frac 0@) Then 
                    Buf 
    Buf " exactly" 
                
    ElseIf (Int(Frac 100@) = Frac 100@) Then 
                    
    If AtLeastOne Then Buf Buf " and " 
                    
    Buf Buf Format$(Frac 100@, "00") & "/100" 
                
    Else 
                    If 
    AtLeastOne Then Buf Buf " and " 
                    
    Buf Buf Format$(Frac 10000@, "0000") & "/10000" 
                
    End If 
                
    English Buf 
            End 
    Function 

            Private Function 
    EnglishDigitGroup(ByVal N As Integer) As String 
                
    Const Hundred " hundred" 
                
    Const One "one" 
                
    Const Two "two" 
                
    Const Three "three" 
                
    Const Four "four" 
                
    Const Five "five" 
                
    Const Six "six" 
                
    Const Seven "seven" 
                
    Const Eight "eight" 
                
    Const Nine "nine" 
                
    Dim Buf As StringBuf "" 
                
    Dim Flag As IntegerFlag False 
                Select 
    Case (N  100
                    Case 
    0Buf ""Flag False 
                    
    Case 1Buf One HundredFlag True 
                    
    Case 2Buf Two HundredFlag True 
                    
    Case 3Buf Three HundredFlag True 
                    
    Case 4Buf Four HundredFlag True 
                    
    Case 5Buf Five HundredFlag True 
                    
    Case 6Buf Six HundredFlag True 
                    
    Case 7Buf Seven HundredFlag True 
                    
    Case 8Buf Eight HundredFlag True 
                    
    Case 9Buf Nine HundredFlag True 
                End Select 
                
    If (Flag <> FalseThen N N Mod 100 
                
    If (0Then 
                    
    If (Flag <> FalseThen Buf Buf " " 
                
    Else 
                    
    EnglishDigitGroup Buf 
                    
    Exit Function 
                
    End If 
                
    Select Case (N  10
                    Case 
    01Flag False 
                    
    Case 2Buf Buf "twenty"Flag True 
                    
    Case 3Buf Buf "thirty"Flag True 
                    
    Case 4Buf Buf "forty"Flag True 
                    
    Case 5Buf Buf "fifty"Flag True 
                    
    Case 6Buf Buf "sixty"Flag True 
                    
    Case 7Buf Buf "seventy"Flag True 
                    
    Case 8Buf Buf "eighty"Flag True 
                    
    Case 9Buf Buf "ninety"Flag True 
                End Select 
                
    If (Flag <> FalseThen N N Mod 10 
                
    If (0Then 
                    
    If (Flag <> FalseThen Buf Buf "-" 
                
    Else 
                    
    EnglishDigitGroup Buf 
                    
    Exit Function 
                
    End If 
                
    Select Case (N
                    Case 
    0
                    Case 
    1Buf Buf One 
                    
    Case 2Buf Buf Two 
                    
    Case 3Buf Buf Three 
                    
    Case 4Buf Buf Four 
                    
    Case 5Buf Buf Five 
                    
    Case 6Buf Buf Six 
                    
    Case 7Buf Buf Seven 
                    
    Case 8Buf Buf Eight 
                    
    Case 9Buf Buf Nine 
                    
    Case 10Buf Buf "ten" 
                    
    Case 11Buf Buf "eleven" 
                    
    Case 12Buf Buf "twelve" 
                    
    Case 13Buf Buf "thirteen" 
                    
    Case 14Buf Buf "fourteen" 
                    
    Case 15Buf Buf "fifteen" 
                    
    Case 16Buf Buf "sixteen" 
                    
    Case 17Buf Buf "seventeen" 
                    
    Case 18Buf Buf "eighteen" 
                    
    Case 19Buf Buf "nineteen" 
                
    End Select 
                EnglishDigitGroup 
    Buf 
            End 
    Function 

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Convert Digits to Words in excel

    This is a duplicate post and as such does not comply with Rule 5 of our forum rules. This thread will now be closed, you may continue in your other thread.

    Thread Closed.
    Hope that helps.

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

    Free DataBaseForm example

Closed Thread

Thread Information

Users Browsing this Thread

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

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