Sub jimin()
Dim r As Integer
Dim i As Integer
Dim arr, brr(1 To 100, 1 To 4)
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Worksheets("汇总")
r = .Cells(.Rows.Count, 1).End(xlUp).Row
arr = .Range("a5:c" & r)
For i = 2 To UBound(arr)
If Not d.exists(arr(i, 2)) Then
m = m + 1
n = n + 1
If m > 10 Then
Exit For
End If
brr(n, 1) = m
brr(n, 2) = arr(i, 1)
brr(n, 3) = arr(i, 2)
brr(n, 4) = arr(i, 3)
d(arr(i, 2)) = m
Else
n = n + 1
brr(n, 1) = d(arr(i, 2))
brr(n, 2) = arr(i, 1)
brr(n, 3) = arr(i, 2)
brr(n, 4) = arr(i, 3)
End If
Next
.Range("e6:h100").ClearContents
.Range("e6").Resize(UBound(brr), UBound(brr, 2)) = brr
End With
End Sub
|