If Temp "" Then Dollars = Temp & Place(Count) & Dollars MyNumber = Trim(Left(MyNumber, DecimalPlace - 1 )) ' Convert cents and set MyNumber to dollar amount.Ĭents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1 ) & _ A better search term would be " vba convert numbers to words".'Main Function Function SpellNumberEDP( ByVal MyNumber, Optional M圜urrency As String = "" ) You may have had couple finding them if you were searching for "convert numbers to text" since that implies changing the data type. (Right(TensText, 1)) 'Retrieve ones placeįunction GetDigit(Digit) 'Converts a number from 1 to 9 into textįraction = Split(n, Application.DecimalSeparator)(1) ' "" Then fractionWords = fractionWords & " "įractionWords = fractionWords & GetDigit(Mid(fraction, x, 1)) If Val(Left(TensText, 1)) = 1 Then 'If value between 10-19 W = "" 'Null out the temporary function value If Mid(numIn, 2, 1) "0" Then 'Convert tens and ones placeįunction GetTens(TensText) 'Converts a number from 10 to 99 into text W = GetDigit(Mid(numIn, 1, 1)) & " Hundred " If InStr(oNum, Application.DecimalSeparator) > 0 Then ' "0" Then 'Convert hundreds place If Temp "" Then LSide = Temp & Place(Count) & LSide RSide = GetTens(Left(Mid(numIn, DecPlace + 1) & "00", 2)) If DecPlace > 0 Then 'Convert Right & set numIn ' Don't change point sign here as the above assignment preserves the point!ĭecPlace = InStr(numIn, ".") 'Pos of dec place 0 if none NumIn = Trim(Str(numIn)) 'String representation of amount Paste the following code into a new module: Option Explicitĭim LSide, RSide, Temp, DecPlace, Count, oNum Two Thousand One Hundred Twenty Three point Four Five Seven Five Edit: I've adapted the procedure below to non-currency, unlimited decimal places.Įdit 2 considers internationalisation via two changes in (1) Function SpellNumber and (2) Function fractionWords to make code work with other decimal separators (e.g.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |