Results 1 to 10 of 11

Thread: Yet Another Number-To-Words Function (Sorry, US Style Only)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    12
    I wrote a function in dutch.
    After some minor adjustments it is also applicable to the English language (correct me if I'm wrong)

    The simplest version I put here: 2 functions & 1 macro.
    For more elaborate functions, including decimal numbers & formatted numbers see

    http://www.snb-vba.eu/VBA_Getallen_naar_tekst_en.html

    Code:
    Function F_mats(y)
      On Error Resume Next
        
      F_mats = Split(Split(" 0 1One 2Two 3Three 4Four 5Five 6Six 7Seven 8Eight 9Nine 10Ten 11Eleven 12Twelve 13Thirteen 15Fifteen 20Twenty 30Thirty 50Fifty 80Eighty ", y)(1))(0)
    End Function
    
    Function F_convert(y)
      F_convert = "invalid input"
      If y = "" Or Val(y) = 0 Then Exit Function
        
      c00 = Format(Val(1 * y), String(3 * ((Len(Format(Val(1 * y))) - 1) \ 3 + 1), "0"))
        
      For j = 1 To Len(c00) \ 3
        x = Mid(c00, 3 * (j - 1) + 1, 3)
            
        sp = Array(F_mats(Left(x, 1)), F_mats(Val(Right(x, 2))), F_mats(Right(x, 1)), F_mats(Mid(x, 2, 1) & "0"), F_mats(Mid(x, 2, 1)))
        c01 = c01 & IIf(sp(0) = "", "", sp(0) & " Hundred ") & IIf(Right(x, 2) = "00", "", IIf(sp(1) <> "", sp(1), IIf(Mid(x, 2, 1) = "1", Trim(sp(2)) & "teen", IIf(sp(3) = "", sp(4) & "ty", sp(3)) & " " & sp(2)))) & Choose(Len(c00) \ 3 - j + 1, "", " Thousand ", " Million ", " Billion ")
      Next
        
      F_convert = IIf(c01 = "", "zero", Replace(c01, "  ", " "))
    End Function
    
    Sub M_tst()
      MsgBox F_convert(InputBox(String(4, vbLf) & "enter a number", "snb")), , "snb"
    End Sub

    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 06-10-2023 at 01:35 PM.

  2. #2
    Junior Member
    Join Date
    May 2015
    Posts
    1
    Rep Power
    0

    Your help is much appreciated

    what if I have 123.20 and convert it into *** ONE HUNDRED TWENTY-THREE AND 20/100 PESOS ONLY ***,

    Thank you for your effort in helping us..

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    19
    Rep Power
    0
    SNB,
    I know it's years later, but I just ran across this post. Testing your function, if I input "451" I get a proper response of "Four Hundred Fifty One". However, if I input "451.27", I get "Thousand Four Hundred Fifty One"

    EDIT: Rick, I saw your note to me, but can't find it on this thread. Note that it's not your function that gave the invalid result, it was the alternative that SNB posted. Have you tested that?
    Last edited by jomili; 06-16-2016 at 02:13 AM.

Similar Threads

  1. Number into words (Rupees)
    By Admin in forum Download Center
    Replies: 2
    Last Post: 06-14-2014, 12:05 AM
  2. Number to Words (Rupees)
    By vishwajeet_chakravorty in forum Excel Help
    Replies: 8
    Last Post: 02-24-2014, 09:26 PM
  3. Excel Number Format: Indian Style Comma Separation
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 6
    Last Post: 09-18-2013, 11:38 AM
  4. Follow-up to "Excel Number Format: Indian Style Comma Separation"
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 2
    Last Post: 04-14-2012, 10:46 PM
  5. Number to Words (Rupees)
    By sa.1985 in forum Excel Help
    Replies: 2
    Last Post: 12-16-2011, 08:57 PM

Tags for this Thread

Posting Permissions

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