kleines Formelproblem
25.02.2008 22:05:00
daniel
ich habe "eigentlich" schon alles fertig
das fehlerhafte Ergebnis tritt nur bei 8stelligen Zahlen auf bei der Excel die Null vorne weg genommen hat.
eigentlich 0223334444
excel macht da draus 223334444
Das Format Standard soll aber nicht verändert werden.
Dim rng As Range, strT As String, intP As Integer
For Each rng In Selection
strT = Replace(Replace(rng, "/", ""), "-", "")
strT = Replace(Replace(strT, ".", "X"), ",", "X")
If Len(strT) = 10 Then 'Falls die Prüfzahl schon vorhanden ist
rng = Format(strT, "00-000-0000/0")
Else
If Len(strT) = 8 Then
MsgBox "Wert ist Fehlerhaft"
End If
If IsNumeric(strT) Then
strT = Right("00000000" & Left(strT, 9), 9)
intP = 4 * Left(strT, 1) + 3 * Left(Right(strT, 8), 1) _
+ 2 * Left(Right(strT, 7), 1) + 7 * Left(Right(strT, 6), 1) _
+ 6 * Left(Right(strT, 5), 1) + 5 * Left(Right(strT, 4), 1) _
+ 4 * Left(Right(strT, 3), 1) + 3 * Left(Right(strT, 2), 1) _
+ 2 * Right(strT, 1)
strT = strT & intP Mod 11
rng = Format(strT, "00-000-0000/0")
End If
End If
Next rng
Selection.EntireColumn.AutoFit
End Sub
Vielen Dank!!!
daniel