G
George Andrews
Dear All
Using Excel 2000
I have adjusted code copied from the MS Knowledge Base to convert Numbers to
Words. The MS version converts to dollars and Cents whereas I need to use
this in Spanish for Euros and Cents.
The code below works for most instances but for the range 100 - 199 and
1000 - 1999 it does not. Can somebody help me with the additional code to
cope with this.
In Spanish, unlike English, there is a special way to say One Hundred and
something i.e. you drop the word ONE and replace the Hundred with 'Ciento'.
Likewise with One Thousand, you drop ONE and replace the Thousand with
'Mil'. From 200 and 2000 the rules are the same as
So as an example:
135 = One Hundred and Thirty Five
135 = Ciento treinta y cinco
235 = Two Hundred and Thirty Five
235 = Dos Cientos Treinta y cinco
1200 = One Thouand two hundred
1200 = Mil Dos Cientos
2200 = Two Thouand two hundred
2200 = Dos Mil Dos Cientos
Ok here is the adapted code. I hope somebody can help.
Regards
George Andrews
..
..
Option Explicit
'****************
' Main Function *
'****************
Function SpellNumber(ByVal MyNumber)
Dim Euros, Centimos, Temp
Dim DecimalPlace, Count
ReDim Place(9) As String
Place(2) = " Mil "
Place(3) = " Millon "
Place(4) = " Billon "
Place(5) = " Trillon "
' String representation of amount.
MyNumber = Trim(Str(MyNumber))
' Position of decimal place 0 if none.
DecimalPlace = InStr(MyNumber, ".")
' Convert cents and set MyNumber to dollar amount.
If DecimalPlace > 0 Then
Centimos = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _
"00", 2))
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If
Count = 1
Do While MyNumber <> ""
Temp = GetHundreds(Right(MyNumber, 3))
If Temp <> "" Then Euros = Temp & Place(Count) & Euros
If Len(MyNumber) > 3 Then
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
Else
MyNumber = ""
End If
Count = Count + 1
Loop
Select Case Euros
Case ""
Euros = "Zero Euros"
Case "Un"
Euros = "Un Euro"
Case Else
Euros = Euros & " Euros"
End Select
Select Case Centimos
Case ""
Centimos = " con Zero Centimos"
Case "Un"
Centimos = " con Un Centimo"
Case Else
Centimos = " con " & Centimos & " Centimos"
End Select
SpellNumber = Euros & Centimos
End Function
'*******************************************
' Converts a number from 100-999 into text *
'*******************************************
Function GetHundreds(ByVal MyNumber)
Dim Result As String
If Val(MyNumber) = 0 Then Exit Function
MyNumber = Right("000" & MyNumber, 3)
' Convert the hundreds place.
If Mid(MyNumber, 1, 1) <> "0" Then
Result = GetDigit(Mid(MyNumber, 1, 1)) & " Cientos "
End If
' Convert the tens and ones place.
If Mid(MyNumber, 2, 1) <> "0" Then
Result = Result & GetTens(Mid(MyNumber, 2))
Else
Result = Result & GetDigit(Mid(MyNumber, 3))
End If
GetHundreds = Result
End Function
'*********************************************
' Converts a number from 10 to 99 into text. *
'*********************************************
Function GetTens(TensText)
Dim Result As String
Result = "" ' Null out the temporary function value.
If Val(Left(TensText, 1)) = 1 Then ' If value between 10-19...
Select Case Val(TensText)
Case 10: Result = "Diez"
Case 11: Result = "Once"
Case 12: Result = "Doce"
Case 13: Result = "Trece"
Case 14: Result = "Catorce"
Case 15: Result = "Quince"
Case 16: Result = "Dieciseis"
Case 17: Result = "Diecisiete"
Case 18: Result = "Dieciocho"
Case 19: Result = "Diecinueve"
Case Else
End Select
Else ' If value between 20-99...
Select Case Val(Left(TensText, 1))
Case 2: Result = "Viente "
Case 3: Result = "Treinta "
Case 4: Result = "Cuarenta "
Case 5: Result = "Cincuenta "
Case 6: Result = "Sesenta "
Case 7: Result = "Setenta "
Case 8: Result = "Ochenta "
Case 9: Result = "Noventa "
Case Else
End Select
Result = Result & GetDigit _
(Right(TensText, 1)) ' Retrieve ones place.
End If
GetTens = Result
End Function
'*******************************************
' Converts a number from 1 to 9 into text. *
'*******************************************
Function GetDigit(Digit)
Select Case Val(Digit)
Case 1: GetDigit = "Un"
Case 2: GetDigit = "Dos"
Case 3: GetDigit = "Tres"
Case 4: GetDigit = "Cuatro"
Case 5: GetDigit = "Cinco"
Case 6: GetDigit = "Seis"
Case 7: GetDigit = "Siete"
Case 8: GetDigit = "Ocho"
Case 9: GetDigit = "Nueve"
Case Else: GetDigit = ""
End Select
End Function
Using Excel 2000
I have adjusted code copied from the MS Knowledge Base to convert Numbers to
Words. The MS version converts to dollars and Cents whereas I need to use
this in Spanish for Euros and Cents.
The code below works for most instances but for the range 100 - 199 and
1000 - 1999 it does not. Can somebody help me with the additional code to
cope with this.
In Spanish, unlike English, there is a special way to say One Hundred and
something i.e. you drop the word ONE and replace the Hundred with 'Ciento'.
Likewise with One Thousand, you drop ONE and replace the Thousand with
'Mil'. From 200 and 2000 the rules are the same as
So as an example:
135 = One Hundred and Thirty Five
135 = Ciento treinta y cinco
235 = Two Hundred and Thirty Five
235 = Dos Cientos Treinta y cinco
1200 = One Thouand two hundred
1200 = Mil Dos Cientos
2200 = Two Thouand two hundred
2200 = Dos Mil Dos Cientos
Ok here is the adapted code. I hope somebody can help.
Regards
George Andrews
..
..
Option Explicit
'****************
' Main Function *
'****************
Function SpellNumber(ByVal MyNumber)
Dim Euros, Centimos, Temp
Dim DecimalPlace, Count
ReDim Place(9) As String
Place(2) = " Mil "
Place(3) = " Millon "
Place(4) = " Billon "
Place(5) = " Trillon "
' String representation of amount.
MyNumber = Trim(Str(MyNumber))
' Position of decimal place 0 if none.
DecimalPlace = InStr(MyNumber, ".")
' Convert cents and set MyNumber to dollar amount.
If DecimalPlace > 0 Then
Centimos = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _
"00", 2))
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If
Count = 1
Do While MyNumber <> ""
Temp = GetHundreds(Right(MyNumber, 3))
If Temp <> "" Then Euros = Temp & Place(Count) & Euros
If Len(MyNumber) > 3 Then
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
Else
MyNumber = ""
End If
Count = Count + 1
Loop
Select Case Euros
Case ""
Euros = "Zero Euros"
Case "Un"
Euros = "Un Euro"
Case Else
Euros = Euros & " Euros"
End Select
Select Case Centimos
Case ""
Centimos = " con Zero Centimos"
Case "Un"
Centimos = " con Un Centimo"
Case Else
Centimos = " con " & Centimos & " Centimos"
End Select
SpellNumber = Euros & Centimos
End Function
'*******************************************
' Converts a number from 100-999 into text *
'*******************************************
Function GetHundreds(ByVal MyNumber)
Dim Result As String
If Val(MyNumber) = 0 Then Exit Function
MyNumber = Right("000" & MyNumber, 3)
' Convert the hundreds place.
If Mid(MyNumber, 1, 1) <> "0" Then
Result = GetDigit(Mid(MyNumber, 1, 1)) & " Cientos "
End If
' Convert the tens and ones place.
If Mid(MyNumber, 2, 1) <> "0" Then
Result = Result & GetTens(Mid(MyNumber, 2))
Else
Result = Result & GetDigit(Mid(MyNumber, 3))
End If
GetHundreds = Result
End Function
'*********************************************
' Converts a number from 10 to 99 into text. *
'*********************************************
Function GetTens(TensText)
Dim Result As String
Result = "" ' Null out the temporary function value.
If Val(Left(TensText, 1)) = 1 Then ' If value between 10-19...
Select Case Val(TensText)
Case 10: Result = "Diez"
Case 11: Result = "Once"
Case 12: Result = "Doce"
Case 13: Result = "Trece"
Case 14: Result = "Catorce"
Case 15: Result = "Quince"
Case 16: Result = "Dieciseis"
Case 17: Result = "Diecisiete"
Case 18: Result = "Dieciocho"
Case 19: Result = "Diecinueve"
Case Else
End Select
Else ' If value between 20-99...
Select Case Val(Left(TensText, 1))
Case 2: Result = "Viente "
Case 3: Result = "Treinta "
Case 4: Result = "Cuarenta "
Case 5: Result = "Cincuenta "
Case 6: Result = "Sesenta "
Case 7: Result = "Setenta "
Case 8: Result = "Ochenta "
Case 9: Result = "Noventa "
Case Else
End Select
Result = Result & GetDigit _
(Right(TensText, 1)) ' Retrieve ones place.
End If
GetTens = Result
End Function
'*******************************************
' Converts a number from 1 to 9 into text. *
'*******************************************
Function GetDigit(Digit)
Select Case Val(Digit)
Case 1: GetDigit = "Un"
Case 2: GetDigit = "Dos"
Case 3: GetDigit = "Tres"
Case 4: GetDigit = "Cuatro"
Case 5: GetDigit = "Cinco"
Case 6: GetDigit = "Seis"
Case 7: GetDigit = "Siete"
Case 8: GetDigit = "Ocho"
Case 9: GetDigit = "Nueve"
Case Else: GetDigit = ""
End Select
End Function