Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao Hermes,
Oltre alla funzionel suggerita da Andrea, e tenendo il mio naso molto stretto tra il pollice e il dito indice, prova la seguente conversione del codice citato in funzione VBA. Questa funzione può essere utilizzata come una funzione del foglio di lavoro normale. Ad esempio inserendo la formula = NumeriInLettere (A1).
'==========>>
Option Explicit
'---------->>
Public Function NumeriInLettere(Rng As Range)
Dim Num As Variant
Dim Num0 As Long, Num1 As Long, Num2 As Long, Num3 As Long
Dim NN As String
Dim Milioni As String
Dim Migliaia As String
Dim LL As String
Dim LLL As String
Dim N(100) As String, M(100) As String
Dim rCell As Range
N(0) = ""
N(1) = "uno"
N(2) = "due"
N(3) = "tre"
N(4) = "quattro"
N(5) = "cinque"
N(6) = "sei"
N(7) = "sette"
N(8) = "otto"
N(9) = "nove"
N(10) = "dieci"
N(11) = "undici"
N(12) = "dodoci"
N(13) = "tredici"
N(14) = "quattordici"
N(15) = "quindici"
N(16) = "sedici"
N(17) = "diciassette"
N(18) = "diciotto"
N(19) = "diciannove"
M(0) = ""
M(2) = "venti"
M(3) = "trenta"
M(4) = "quaranta"
M(5) = "cinquanta"
M(6) = "sessanta"
M(7) = "settanta"
M(8) = "ottanta"
M(9) = "novanta"
M(10) = "Cento"
Num = Rng.Value
NN = LTrim(Str(Num))
If Len(NN) > 6 Then
Milioni = Left(NN, Len(NN) - 6)
NN = Right(NN, 6)
End If
If Len(NN) > 3 Then
Migliaia = Left(NN, Len(NN) - 3)
NN = Right(NN, 3)
End If
GoSub Ciclo
LLL = LL
NN = Migliaia
If Migliaia = "1" Then
LLL = "mille" + LLL
Else
GoSub Ciclo
If Len(LL) > 0 Then LLL = LL + "mila" + LLL
End If
NN = Milioni
If Milioni = "1" Then
LLL = "unmilione" + LLL
Else
GoSub Ciclo
If Len(LL) > 0 Then LLL = LL + "milioni" + LLL
End If
' Range("g3:g787").Select
NumeriInLettere = LLL
GoTo Fine
Ciclo:
LL = ""
Num0 = Val(NN)
If Len(NN) = 2 Then NN = "0" + NN
If Len(NN) = 1 Then NN = "00" + NN
Num3 = Val(Right(NN, 1))
Num2 = Val(Mid(NN, 2, 1))
Num1 = Val(Left(NN, 1))
If Num0 > 99 Then
If Num0 > 199 Then LL = N(Num1)
LL = LL + "cento"
End If
If Num2 > 1 Then
LL = LL + M(Num2)
If Num3 > 0 Then
If Num3 = 1 Or Num3 = 8 Then LL = Left(LL, Len(LL) - 1)
LL = LL + N(Num3)
End If
End If
If Num2 < 2 Then
LL = LL + N(Num3 + Num2 * 10)
End If
Return
Fine:
End Function
'<<==========
La funzione può essere utilizzata anche in VBA, ad esempio, come segue:
'==========>>
Public Sub Demo()
Dim srcRng As Range
Dim destRng As Range
Dim i As Long
Set srcRng = ActiveSheet.Range("A1:A20")
Set destRng = srcRng.Offset(0, 3)
For i = 1 To srcRng.Cells.Count
destRng.Cells(i).Value = NumeriInLettere(srcRng.Cells(i))
Next i
End Sub
'<<==========
Tuttavia, preferisco la traduzione suggerita da Andrea!!
===
Regards,
Norman