Moderatori: Anthony47, Flash30005
michaltam78 ha scritto:Ho trovato un modo per farlo!! Si tratta di un addin trovato in giro per la rete!
Sub ConvertiNumInLettere()
Num = [A1]
LNum = Len(Num)
Dim VN(105) As String
Dim VP(5) As String
VN(0) = "zero"
VN(1) = "uno"
VN(2) = "due"
VN(3) = "tre"
VN(4) = "quattro"
VN(5) = "cinque"
VN(6) = "sei"
VN(7) = "sette"
VN(8) = "otto"
VN(9) = "nove"
VN(10) = "dieci"
VN(11) = "undici"
VN(12) = "dodici"
VN(13) = "tredici"
VN(14) = "quattordici"
VN(15) = "quindici"
VN(16) = "sedici"
VN(17) = "diciassette"
VN(18) = "diciotto"
VN(19) = "diciannove"
VN(20) = "venti"
VN(30) = "trenta"
VN(40) = "quaranta"
VN(50) = "cinquanta"
VN(60) = "sessanta"
VN(70) = "settanta"
VN(80) = "ottanta"
VN(90) = "novanta"
VN(100) = "cento"
VP(1) = "mila"
If Len(Format(Num, "#,##0")) = 5 And Left(Num, 1) = 1 Then VP(1) = "mille"
VP(2) = "milioni"
If Len(Format(Num, "#,##0")) = 9 And Left(Num, 1) = 1 Then VP(2) = "milione"
VP(3) = "miliardi"
If Len(Format(Num, "#,##0")) = 13 And Left(Num, 1) = 1 Then VP(3) = "miliardo"
VP(4) = "trilioni"
If Len(Format(Num, "#,##0")) = 17 And Left(Num, 1) = 1 Then VP(4) = "trilione"
VP(5) = "triliardi"
If Len(Format(Num, "#,##0")) = 21 And Left(Num, 1) = 1 Then VP(5) = "triliardo"
NFin = ""
LLN = Len(Format(Num, "#,##0"))
CP = 0
For Col = 1 To LLN
If Mid(Format(Num, "#,##0"), Col, 1) = "." Then CP = CP + 1
Next Col
Col = 1
AggM = ""
PEcc = 0
If CP > 5 Then
MsgBox "Attenzione superato limite numerico", vbExclamation
Exit Sub
End If
For ColN = 1 To LLN
AggM = VP(CP)
CP = CP - 1
If CP < 0 Then CP = 0
Col = ColN
Campo = ""
Call RiempiCampo
If PEcc = 0 Then
If Len(Format(Num, "#,##0")) = 9 Or Len(Format(Num, "#,##0")) = 13 Or Len(Format(Num, "#,##0")) = 17 Or Len(Format(Num, "#,##0")) = 21 Then VN(1) = "un"
If Len(Format(Num, "#,##0")) = 5 Then VN(1) = ""
PEcc = 1
Else
VN(1) = "uno"
End If
LNum = Len(Campo)
ColN = Col
Ini:
Select Case LNum
Case 3
NumC = Mid(Campo, Len(Campo) - 2, 1)
If NumC <> 1 Then
NFin = NFin & VN(NumC) & VN(100)
Else
NFin = NFin & VN(100)
End If
LNum = 2
GoTo Ini:
Case 2
NumD = Right(Campo, 2)
If NumD > 20 Then
NFin = NFin & VN(Val(Left(NumD, 1) * 10))
If Right(NumD, 1) = 1 Then NFin = Left(NFin, Len(NFin) - 1)
If Right(NumD, 1) <> 0 Then
LNum = 1
GoTo Ini:
End If
Else
If NumD <> 0 Then NFin = NFin & VN(NumD) & AggM
End If
Case 1
NumU = Right(Campo, 1)
If NumU = 0 Then
NFin = NFin & AggM
If NFin = "" Then NFin = VN(NumU)
Else
NFin = NFin & VN(NumU) & AggM
End If
End Select
SaltaC:
Next ColN
[B1] = StrConv(NFin, vbProperCase)
End Sub
Sub RiempiCampo()
Do Until Mid(Format(Num, "#,##0"), Col, 1) = "."
Campo = Campo & Mid(Format(Num, "#,##0"), Col, 1)
Col = Col + 1
If Col > LLN Then Exit Do
Loop
Campo = Val(Campo)
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then Call ConvertiNumInLettere
End Sub
Public Col, LLN As Integer, Campo, NFin As String, Num As Double
Next ColN
NFin = Replace(Replace(NFin, "tiotto", "totto"), "taotto", "totto") '<<<< aggiunta
[B1] = StrConv(NFin, vbProperCase)
End Sub
=SpellIt(IlNumero;iDecimali)
Option Base 1
Dim sSpell As String
Function SpellIt(ByVal myValore As Double, Optional ByVal myDec As Integer = 2) As String
'traduce un valore nel suo spelling, by Anthony47
'
'Uso:
' =SPELLIT(ValoreNumerico [;NumDecimali])
' NumDecimali e' opzionale, di default viene usato 2
'
'Esempio
'=SPELLIT(456,789) restituira' "quattrocentocinquantasei/79"
'
'Max ValNumerico = 2.147.483.647
'I Negativi vengono rappresentati come "-(Spelling)"
'
Dim sValore As String, sPotenza, uPotenza, I As Long, myMille As String, vValore As Long
'
sSpell = ""
'Valori chiave e sostituzioni
sPotenza = Array("miliardi.", "milioni.", "mila.", "")
uPotenza = Array("unmiliardo.", "unmilione.", "mille.", "")
'
sValore = Format(Abs(Fix(myValore)), "000000000000")
vValore = Int(Abs(myValore))
'
For I = 1 To 4 '4 blocchi "migliaia"
myMille = Mid(sValore, 1 + (I - 1) * 3, 3)
If CLng(myMille) > 0 Then
If CLng(myMille) = 1 Then
sSpell = sSpell & uPotenza(I)
Else
sSpell = sSpell & sMille(myMille) & sPotenza(I)
End If
End If
Next I
'Compila spelling
If sSpell = "" Then sSpell = "zero"
If myDec > 0 Then myVirg = "/" & Round((Abs(myValore) - vValore) * (10 ^ myDec), 0)
SpellIt = sSpell & myVirg
If myValore < 0 Then SpellIt = "-(" & SpellIt & ")"
End Function
Function sMille(ByVal sBlocco As String) As String
Dim vNum, sNum, vBlocco As Long, nwBlocco As String, strNum As String
Dim Iv As Long
'
'Valori chiave
vNum = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, _
30, 40, 50, 60, 70, 80, 90, 100)
sNum = Array("", "uno", "due", "tre", "quattro", "cinque", "sei", "sette", "otto", "nove", "dieci", "undici", _
"dodici", "tredici", "quattordici", "quindici", "sedici", "diciassette", "diciotto", "diciannove", "venti", _
"trenta", "quaranta", "cinquanta", "sessanta", "settanta", "ottanta", "novanta", "cento")
If Len(sBlocco) > 3 Then 'Sara' sempre Falso
sMille = "#####": Exit Function
End If
'
strNum = sBlocco
ReBlk:
vBlocco = CLng(strNum)
If vBlocco > 99 Then
nwBlocco = Left(strNum, 1)
If vBlocco > 199 Then
txt1 = sMille(nwBlocco) & "cento"
strNum = Replace(strNum, nwBlocco, "", 1, 1)
Else
txt1 = "cento"
strNum = Replace(strNum, nwBlocco, "", 1, 1)
End If
End If
If vBlocco > 199 Then GoTo ReBlk
If vBlocco <= 20 Then GoTo Fase3
Fase2:
vBlocco = CLng(strNum)
CPart = Application.Match(vBlocco, vNum)
txt2 = sNum(CPart)
CVal = vNum(CPart)
vBlocco = vBlocco - CVal
Fase3:
If vBlocco > 0 Then
txt3 = sNum(vBlocco + 1)
' txt3 = sMille(Format(vBlocco, "0"))
End If
'
'Compila spelling
If (Left(txt3, 1) = "u" Or Left(txt3, 1) = "o") And Len(txt2) > 0 Then _
txt2 = Left(txt2, Len(txt2) - 1)
sMille = txt1 & txt2 & txt3
End Function
Torna a Applicazioni Office Windows
Excel: problema con date se devo unirle a testi Autore: valle1975 |
Forum: Applicazioni Office Windows Risposte: 3 |
confrontare e evidenziare 2 fogli excel Autore: niccia |
Forum: Applicazioni Office Windows Risposte: 5 |
[EXCEL] controllo corrispondenza tra valori con un vincolo Autore: sbs |
Forum: Applicazioni Office Windows Risposte: 9 |
Visitano il forum: Nessuno e 16 ospiti