excel - How to change the cents form of SpellNumber macro function to "xx/100" -
i have spell numbers in excel need cents form "xx/100" ex. 3,258.63 = "three thousand 2 hundred fifty 8 hundred 63/100 only"
right macro function
option explicit 'main function '=spellnumber(95) sub test() msgbox spellnumber(95) end sub function spellnumber(mynumber, optional bmoney = false) dim dollars, cents, temp dim decimalplace, count dim inumber redim place(9) string place(1) = " hundred " place(2) = " thousand " place(3) = " million " place(4) = " billion " place(5) = " trillion " inumber = mynumber ' string representation of amount. mynumber = trim(str(mynumber)) ' position of decimal place 0 if none. decimalplace = instr(mynumber, ".") ' convert cents , set mynumber dollar amount. if decimalplace > 0 cents = gettens(left(mid(mynumber, decimalplace + 1) & _ "00", 2)) mynumber = trim(left(mynumber, decimalplace - 1)) end if count = 1 while mynumber <> "" temp = gethundreds(right(mynumber, 3)) if temp <> "" dollars = temp & place(count) & dollars if len(mynumber) > 3 mynumber = left(mynumber, len(mynumber) - 3) else mynumber = "" end if count = count + 1 loop if bmoney = true select case dollars case "" dollars = "no dollars" case "one" dollars = "one dollar" case else dollars = dollars & " dollars" end select select case cents case "" cents = " , no cents" case "one" cents = " , 1 cent" case else cents = " , " & cents & " cents" end select end if spellnumber = dollars & cents end function function gethundreds(byval mynumber) dim result string if val(mynumber) = 0 exit function mynumber = right("000" & mynumber, 3) ' convert hundreds place. if mid(mynumber, 1, 1) <> "0" result = getdigit(mid(mynumber, 1, 1)) & " hundred " end if ' convert tens , ones place. if mid(mynumber, 2, 1) <> "0" result = result & gettens(mid(mynumber, 2)) else result = result & getdigit(mid(mynumber, 3)) end if gethundreds = result end function function gettens(tenstext) dim result string result = "" ' null out temporary function value. if val(left(tenstext, 1)) = 1 ' 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 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
but gives me spelling on cents well, how can leave cents in numbers in format of 50/100?
many in advance help
this getting fraction part.
right(formatcurrency(mynumber, 2), 2) & "/100"
Comments
Post a Comment