第一题的答案,这个人的方法个人觉得最佳!
Sub mscmsc()
Dim Arr, d, dd, mh As Integer, hbstr
Set d = CreateObject("scripting.dictionary")
Set dd = CreateObject("scripting.dictionary")
mh = Cells(65536, 1).End(xlUp).Row
Arr = ActiveSheet.Range("a1:e" & mh)
For i = 2 To UBound(Arr)
hbstr = Arr(i, 1) & Arr(i, 3) & Arr(i, 4)
If d.Exists(Arr(i, 4)) Then
If dd.Exists(hbstr) Then
Arr(i, 5) = dd(hbstr)
Else
d(Arr(i, 4)) = d(Arr(i, 4)) + 1
dd(hbstr) = d(Arr(i, 4))
Arr(i, 5) = dd(hbstr)
End If
Else
Arr(i, 5) = 1
d(Arr(i, 4)) = Arr(i, 5)
dd(hbstr) = Arr(i, 5)
End If
Next
Range("e1:e" & mh) = Application.Index(Arr, , 5)
End Sub |