|
- Sub test2()
- Dim r%, i%
- Dim arr, brr(1 To 5, 1 To 5)
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:c" & r)
- End With
- For i = 1 To UBound(brr) - 1
- Set d(i) = CreateObject("scripting.dictionary")
- Next
- For i = 1 To UBound(arr)
- Select Case arr(i, 2)
- Case Is <= 10
- m = 1
- Case Is <= 50
- m = 2
- Case Is <= 100
- m = 3
- Case Else
- m = 4
- End Select
- If Not d(m).exists(arr(i, 1)) Then
- ReDim crr(1 To 2)
- crr(1) = arr(i, 2)
- crr(2) = arr(i, 3)
- Else
- crr = d(m)(arr(i, 1))
- crr(1) = crr(1) & "+" & arr(i, 2)
- crr(2) = crr(2) & "+" & arr(i, 3)
- End If
- d(m)(arr(i, 1)) = crr
- brr(m, 2) = brr(m, 2) + arr(i, 2)
- brr(m, 3) = brr(m, 3) + arr(i, 3)
- Next
- For i = 1 To UBound(brr) - 1
- For Each bb In d(i).keys
- crr = d(i)(bb)
- brr(i, 4) = brr(i, 4) & vbLf & bb & "," & crr(1)
- brr(i, 5) = brr(i, 5) & vbLf & bb & "," & crr(2)
- Next
- brr(i, 1) = d(i).Count
- Next
- For i = 1 To UBound(brr)
- For j = 4 To 5
- If Len(brr(i, j)) <> 0 Then
- brr(i, j) = Mid(brr(i, j), 2)
- End If
- Next
- Next
- For j = 1 To 3
- For i = 1 To UBound(brr) - 1
- brr(UBound(brr), j) = brr(UBound(brr), j) + brr(i, j)
- Next
- Next
- With Worksheets("sheet3")
- .Range("b2").Resize(UBound(brr), UBound(brr, 2)) = brr
- End With
- End Sub
复制代码 |
|