|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 7).End(xlUp).Row
- .Range("i2:l" & r).ClearContents
- brr = .Range("g2:l" & r)
- For i = 1 To UBound(brr)
- d(brr(i, 1)) = i
- Next
- qsrs = .Range("f1")
- yxrs = .Range("f2")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- .Range("a1:c" & r).Sort key1:=.Range("c2"), order1:=xlDescending, Header:=xlYes
- arr = .Range("a2:c" & r)
-
- For i = 1 To UBound(arr)
- If Not d1.exists(arr(i, 2)) Then
- m = 1
- ReDim crr(1 To 3, 1 To m)
- Else
- crr = d1(arr(i, 2))
- m = UBound(crr, 2) + 1
- ReDim Preserve crr(1 To 3, 1 To m)
- End If
- For j = 1 To 3
- crr(j, m) = arr(i, j)
- Next
- d1(arr(i, 2)) = crr
- Next
- For Each aa In d1.keys
- crr = d1(aa)
- ReDim drr(1 To UBound(crr, 2), 1 To UBound(crr))
- For i = 1 To UBound(crr)
- For j = 1 To UBound(crr, 2)
- drr(j, i) = crr(i, j)
- Next
- Next
- d1(aa) = drr
- Next
- For i = 1 To Application.Min(UBound(arr), yxrs)
- If d.exists(arr(i, 2)) Then
- m = d(arr(i, 2))
- brr(m, 3) = brr(m, 3) + 1
- End If
- Next
- For i = 1 To UBound(brr)
- If d1.exists(brr(i, 1)) Then
- crr = d1(brr(i, 1))
- For k = 1 To Application.Min(UBound(crr), brr(i, 2))
- If crr(k, 3) + 40 >= yxfs Then
- brr(i, 4) = brr(i, 4) + 1
- End If
- Next
- End If
- Next
- yxfs = arr(Application.Min(UBound(arr), yxrs), 3)
- .Range("g2").Resize(UBound(brr), UBound(brr, 2)) = brr
- End With
- End Sub
复制代码 |
|