Option Explicit
Sub test()
Dim arr, pos(1), i, j, k, m, t, dic
Set dic = CreateObject("scripting.dictionary")
pos(0) = Array(1, 2, 3, 6)
pos(1) = Array(4, 5, 7, 8, 9)
arr = Sheets("数据源 ").[a1].CurrentRegion.Offset(1).Resize(, 10)
For i = 1 To UBound(arr, 1) - 1
t = arr(i, pos(0)(0))
For j = 1 To UBound(pos(0))
t = t & arr(i, pos(0)(j))
Next
If dic.exists(t) Then
For k = 0 To UBound(pos(1))
arr(dic(t), pos(1)(k)) = arr(dic(t), pos(1)(k)) + arr(i, pos(1)(k))
Next
Else
m = m + 1: dic(t) = m
For k = 1 To UBound(arr, 2) - 1
arr(m, k) = arr(i, k)
Next
End If
Next
For i = 1 To m
If arr(i, 8) <> 0 Then arr(i, 10) = arr(i, 4) / arr(i, 8) * 100
Next
With Sheets("汇总表").[a3]
.Resize(Rows.Count - 2, UBound(arr, 2) + 1).ClearContents
.Resize(m, UBound(arr, 2)) = arr
End With
End Sub |