|
- Sub test1() '字典法
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:e" & r)
- For i = 1 To UBound(arr)
- xm = arr(i, 1) & "+" & arr(i, 2)
- If Not d.exists(xm) Then
- ReDim brr(1 To 4)
- brr(1) = arr(i, 1)
- brr(2) = arr(i, 2)
- Else
- brr = d(xm)
- End If
- brr(3) = brr(3) + arr(i, 4)
- brr(4) = brr(4) + arr(i, 5)
- d(xm) = brr
- Next
- .Range("g2").Resize(d.Count, 4) = Application.Transpose(Application.Transpose(d.items))
- End With
- End Sub
复制代码 |
|