Advertisement
B1rkh0ff

NumToWords Excel

Oct 23rd, 2024 (edited)
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function NumToWords(ByVal MyNumber As Double, ByVal CurrencyName As String) As String
  2.     Dim Units As String
  3.     Dim TempStr As String
  4.     Dim Count As Integer
  5.     Dim UnitsDigit As String
  6.     Dim UnitsWords(9) As String
  7.  
  8.     ' Defines arrays for unit names
  9.    UnitsWords(1) = "un": UnitsWords(2) = "deux": UnitsWords(3) = "trois": UnitsWords(4) = "quatre"
  10.     UnitsWords(5) = "cinq": UnitsWords(6) = "six": UnitsWords(7) = "sept": UnitsWords(8) = "huit"
  11.     UnitsWords(9) = "neuf"
  12.  
  13.     ' Process the number
  14.    Count = 1
  15.     Do While MyNumber <> ""
  16.         UnitsDigit = Right(MyNumber, 1)
  17.         TempStr = UnitsWords(CInt(UnitsDigit)) & " " & TempStr
  18.         MyNumber = Left(MyNumber, Len(MyNumber) - 1)
  19.         Count = Count + 1
  20.     Loop
  21.  
  22.     ' Return the number in words followed by the currency
  23.    NumToWords = Trim(TempStr) & " " & CurrencyName
  24. End Function
  25.  
Tags: NumToWords
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement