In excel la massima precisione ottenibile e’ di 15 digit; Long e’ un data type che si ferma a 10 digit; quindi dichiarando J as Double e usando 921210505004801 / 921210505004804 (i valori che hai citato) il risultato a me viene ancora buono.
Aggiungendo 1 ulteriore digit andra’ in crisi gia’ l’ input in I3, e a cascata i calcoli della macro.
Nella situazione che descrivi, cioe' con lunghezze potenzialmente superiori a 15 digit, suggerisco:
-introdurre i dati in col I e J sotto forma di stringa
-usare una nuova macro che spezzi questa stringa in una parte inferiore di N cifre, che sara’ usato per il ciclo For J /Next J, e una parte superiore che sara’ semplicemente concatenata col risultato del ciclo.
N variera’ da 5 a 10, e corrispondera’ alla prima cifra inferiore a 9 che sara’ trovata scorrendo il numero in J3 da destra verso sinistra e partendo dal quartultimo carattere.
La nuova macro:
- Codice: Seleziona tutto
Sub sebn2()
Dim LastI As Long, I As Long, J As Long, myLow As Long, myUp As String, myLC As Long
'
myLC = 3
'
LastI = Range("I3").End(xlDown).Row
For I = 3 To LastI
If IsNumeric(CDbl(Cells(I, "I"))) And IsNumeric(CDbl(Cells(I, "J"))) Then
For J = Len(Cells(I, "I")) - 3 To 1 Step -1
If Mid(Cells(I, "I"), J) < "9" Then myLC = Len(Cells(I, "I")) - J + 1: Exit For
Next J
mymess = "": myUp = "": DoEvents
myLow = CLng(Right(Cells(I, "I"), myLC))
If Len(CStr(Cells(I, "I"))) > myLC Then myUp = Left(CStr(Cells(I, "I")), Len(CStr(Cells(I, "I"))) - myLC)
If CLng(Right(Cells(I, "J"), myLC)) < myLow Then mytop = (CLng(Right(Cells(I, "J"), myLC)) + 100000) Else mytop = CLng(Right(Cells(I, "J"), myLC))
For J = myLow To mytop
DoEvents
If myUp = "" Then
mymess = mymess & J & "; "
Else
mymess = mymess & myUp & Format(J, String(myLC, "0")) & "; "
End If
Next J
If Len(mymess) > 3 Then Cells(I, "L") = Left(mymess, Len(mymess) - 2)
End If
Next I
End Sub
Ciao