- Sub test()
- Dim i%, arr, d, d1
- arr = Sheets("Original").[a1].CurrentRegion
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- For i = 2 To UBound(arr)
- d(arr(i, 13)) = d(arr(i, 13)) + arr(i, 16)
- d1(arr(i, 13)) = d1(arr(i, 13)) + arr(i, 20)
- Next
- arr = Sheets("Data").[a1].CurrentRegion
- For i = 2 To UBound(arr)
- If d.exists(arr(i, 1)) Then
- arr(i, 2) = arr(i, 2) + d(arr(i, 1))
- arr(i, 3) = arr(i, 3) + d1(arr(i, 1))
- arr(i, 4) = arr(i, 3) / arr(i, 2)
- End If
- Next
- Sheets("Data").[a1].Resize(UBound(arr), UBound(arr, 2)) = arr
- End Sub
复制代码 |