Results 1 to 4 of 4

Help to Modify the code to spell Numbers to words

Threaded View

  1. #1
    Registered User
    Join Date
    02-05-2017
    Location
    Kuwait, Kuwait
    MS-Off Ver
    2010
    Posts
    3

    Help to Modify the code to spell Numbers to words

    Hi everyone,
    i need your help please,
    i searched and i got the below code and i changed the Currency and it is working well but it only Spell 2 digits decimal after dot. will you please help me to change it to spell 3 digit decimal like: "100.755" to "One Hundred Dinar and Seven Hundred Fifty Five Fils." appreciate your help.
    Option Explicit
    
    'Main Function
    Function USD(ByVal MyNumber)
       Dim Dinars, Fils, 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 Fils and set MyNumber to Dinar amount.
       If DecimalPlace > 0 Then
          Fils = 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 Dinars = Temp & Place(Count) & Dinars
          If Len(MyNumber) > 3 Then
             MyNumber = Left(MyNumber, Len(MyNumber) - 3)
          Else
             MyNumber = ""
          End If
          Count = Count + 1
       Loop
       Select Case Dinars
          Case ""
             Dinars = "No Dinars"
          Case "One"
             Dinars = "One Dinar"
          Case Else
             Dinars = Dinars & " Dinars"
       End Select
          Select Case Fils
          Case ""
             Fils = " and No Fils"
          Case "One"
             Fils = " and One Fils"
          Case Else
             Fils = " and " & Fils & " Fils"
       End Select
       USD = Dinars & Fils
    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
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. The code is also very difficult to read, I have added indentation to make it more readable. --6StringJazzer
    Last edited by 6StringJazzer; 02-15-2017 at 12:29 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Spell Number VBA coding for Arabic words
    By arshad.99.ali in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-20-2016, 04:44 AM
  2. Spell Numbers to arabic Words
    By Amrbahgat in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-18-2014, 03:10 AM
  3. spell the numbers in words
    By israrkhan in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-13-2014, 10:46 AM
  4. Replies: 5
    Last Post: 07-10-2012, 02:30 PM
  5. How does Excel spell out numbers in words ?
    By Kat in forum Excel General
    Replies: 1
    Last Post: 06-20-2006, 09:35 PM
  6. [SOLVED] Spell Checking - Special Words Not Picked Up by Excel
    By Hans Emilio in forum Excel General
    Replies: 4
    Last Post: 05-25-2005, 09:42 AM
  7. How do I spell numbers as words for writing checks in Excel?
    By Heather in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-11-2005, 05:06 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