|
Sub qs() '2024/7/6
Dim arr, brr, dic, i
Set dic = CreateObject("scripting.dictionary")
With Sheet1
arr = .Range("a1").CurrentRegion.Value
ReDim brr(1 To UBound(arr), 1 To 4)
For i = 2 To UBound(arr)
s = arr(i, 1) & "|" & arr(i, 2)
If Not dic.exists(s) Then
m = m + 1
dic(s) = m
brr(m, 1) = arr(i, 1): brr(m, 2) = arr(i, 2): brr(m, 3) = Val(arr(i, 3)): brr(m, 4) = Val(arr(i, 4))
Else
r = dic(s)
brr(r, 3) = brr(r, 3) + Val(arr(i, 3)): brr(r, 4) = brr(r, 4) + Val(arr(i, 4))
End If
Next
.Range("f1:i10000").ClearContents
.Range("f1").Resize(1, 4) = Application.Index(arr, 1, 0)
.Range("f2").Resize(m, 4) = brr
End With
Set dic = Nothing
End Sub |
|