Изменил код и все заработало
| Код |
|---|
Dim Rng As Range, maxValue As Long
Set Rng = Range("B3:B20000")
maxValue = Application.WorksheetFunction.Max(Rng)
Dim iLastRow As Long
iLastRow = Cells(Rows.Count, 2).End(xlUp).Row
Dim arr As Variant
arr = Range("B1:B" & iLastRow).Value
Dim iCurRow As Long, curValue As Long
For iCurRow = 1 To UBound(arr, 1)
If Not IsEmpty(arr(iCurRow, 1)) Then
Dim strValue As String
strValue = CStr(arr(iCurRow, 1))
If Len(strValue) > 4 Then
Dim numberPart As String
numberPart = Mid(strValue, 5)
If IsNumeric(numberPart) Then
curValue = CLng(numberPart)
If maxValue < curValue Then maxValue = curValue
End If
ElseIf IsNumeric(strValue) Then
curValue = CLng(strValue)
If maxValue < curValue Then maxValue = curValue
End If
End If
Next
Cells(iLastRow + 1, 2) = Left(Cells(iLastRow + 1, 3), 3) & Format(maxValue + 1, "_000000") |