Hi everyone,
What is the VBA code for converting percentage value to English Word.
Example:
85.51 = Eighty Five point Fifty One Percent
91.00 = Ninety One Percent
7.11 = Seven point Eleven Percent
Thank you in advance
Hi everyone,
What is the VBA code for converting percentage value to English Word.
Example:
85.51 = Eighty Five point Fifty One Percent
91.00 = Ninety One Percent
7.11 = Seven point Eleven Percent
Thank you in advance
Last edited by chergian; 03-15-2017 at 04:57 AM.
Maybe :
![]()
'Function F_convert() and F_mats() are taken from "http://www.snb-vba.eu/VBA_Getallen_naar_tekst_en.html" Private Function F_convert(y) F_convert = "Invalid input" 'If y = "" Or Val(y) = 0 Then Exit Function If y = "" 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 Private 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 Private Function F_percent(y As String) If Len(y) Then v = Split(y, ".") F_percent = Application.Proper(F_convert(CLng(v(0)))) If UBound(v) = 1 Then F_percent = F_percent & " point " & F_convert(CLng(v(1))) F_percent = F_percent & " Percent" End If End Function Sub Test() Debug.Print F_percent("") Debug.Print F_percent("0") Debug.Print F_percent("85") Debug.Print F_percent("85.51") Debug.Print F_percent("7.11") End Sub
1. I care dog
2. I am a loop maniac
3. Forum rules link : Click here
3.33. Don't forget to mark the thread as solved, this is important
Thank you so much karedog.... But there are something wrong with .01 to .09, it's spell this way:
Example:
90.01 spell as "Ninety point One Percent" - instead "Ninety point Zero One Percent"
90.02 spell as "Ninety point Two Percent" - instead "Ninety point Zero Two Percent"
...and up to .09...
Hope you get my point...
Replace the F_percent() function above with this :
And don't forget to mark this thread as solved :![]()
Private Function F_percent(y As String) If Len(y) Then v = Split(y, ".") F_percent = Application.Proper(F_convert(CLng(v(0)))) If UBound(v) = 1 Then v(1) = Left$(v(1), 2) If Left$(v(1), 1) = "0" Then F_percent = Application.Proper(F_percent & " point Zero " & F_convert(CLng(Right$(v(1), 1)))) Else F_percent = Application.Proper(F_percent & " point " & F_convert(CLng(v(1)))) End If F_percent = F_percent & " Percent" End If End Function
select Thread Tools from the menu link above and mark this thread as SOLVED.
You are welcome, thanks for marking the thread as solved and for the rep.points.
Regards
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks