Option Explicit
Sub TEST2()
Dim ar, br(), i&, j&, n&, p&, r&
ar = [A1].CurrentRegion.Value: p = 2
For i = 2 To UBound(ar)
If i = UBound(ar) Then
r = r + 1
ReDim Preserve br(1 To 2, 1 To r)
br(1, r) = p: br(2, r) = i
Else
If ar(i + 1, 6) <> ar(p, 6) Then
r = r + 1
ReDim Preserve br(1 To 2, 1 To r)
br(1, r) = p: br(2, r) = i
p = i + 1
End If
End If
Next i
For j = 1 To UBound(br, 2)
If br(2, j) - br(1, j) > 0 Then
n = 0
For i = br(1, j) To br(2, j)
n = n + 1
ar(i, 6) = ar(i, 6) & n
Next i
End If
Next j
[I1].Resize(UBound(ar), UBound(ar, 2)) = ar
Beep
End Sub
|