发现没有人使用字典+数组,自己用字典+数组做了一个:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(0, 0) <> "A2" Then Exit Sub
Dim arr, brr(1 To 34, 1 To 15), crr(), aa, d, h, i, j, k, a()
s = Sheet1.Range("a65536").End(xlUp).Row
arr = Sheet1.Range("a2:E" & s)
ReDim crr(1 To UBound(arr), 1 To 5)
ReDim a(1 To UBound(arr))
r = 0
For i = 1 To UBound(arr)
If arr(i, 1) = Range("a2") Then
m = m + 1
crr(m, 1) = arr(i, 2): crr(m, 2) = arr(i, 3): crr(m, 3) = arr(i, 4): crr(m, 4) = arr(i, 5)
crr(m, 5) = arr(i, 5) + arr(i, 3) + arr(i, 4)
a(m) = arr(i, 5) + arr(i, 3) + arr(i, 4)
End If
Next
Set d = CreateObject("Scripting.Dictionary")
For i = m To 1 Step -1
u = u + 1
b = Application.Small(a, i)
If Not d.exists(b) Then
d(b) = u
End If
Next
w = d.keys
For j = 0 To UBound(w)
For h = 1 To m
If crr(h, 5) = w(j) Then
ss = ss + 1
If ss < 35 Then
brr(ss, 1) = d(crr(h, 5))
brr(ss, 2) = crr(h, 1): brr(ss, 3) = crr(h, 2): brr(ss, 4) = crr(h, 3): brr(ss, 5) = crr(h, 4): brr(ss, 6) = crr(h, 5)
Else
aa = aa + 1
brr(aa, 9) = d(crr(h, 5))
brr(aa, 10) = crr(h, 1): brr(aa, 11) = crr(h, 2): brr(aa, 12) = crr(h, 3): brr(aa, 13) = crr(h, 4): brr(aa, 14) = crr(h, 5)
End If
End If
Next
Next
Range("a35").Resize(34, 15) = brr
End Sub
|