請試看看,謝謝。
Sub test()
Dim Arr, xD, Ar(), T, T2%, i&, M%, N%
Set xD = CreateObject("Scripting.Dictionary")
Sheets("工作表1").Range("B1:C1").Copy Sheets("Summary").Range("A1")
Arr = Sheets("工作表1").[a1].CurrentRegion
ReDim Ar(1 To UBound(Arr), 1 To 2)
For i = 2 To UBound(Arr)
T = Arr(i, 2): T2 = Arr(i, 3)
If xD.Exists(T & "") Then
M = xD(T & "")
Ar(M, 2) = Ar(M, 2) + T2
Else
N = N + 1: xD(T & "") = N
Ar(N, 1) = T: Ar(N, 2) = T2
End If
Next
Sheets("Summary").[A2].Resize(N, 2) = Ar
End Sub作者: samwang 時間: 2021-5-17 07:52
Option Explicit
Sub TEST_1()
Dim Brr, Crr, Z, i&, j%, R&, Y&, T$
Set Z = CreateObject("Scripting.Dictionary")
Brr = Range([工作表1!D1], [工作表1!A65536].End(3))
ReDim Crr(1 To UBound(Brr), 1 To 3)
For i = 1 To UBound(Brr)
T = Brr(i, 2) & "|" & Brr(i, 4)
R = Z(T)
If R = 0 Then
Y = Y + 1: R = Y
For j = 1 To 3: Crr(R, j) = Brr(i, j + 1): Next
Z(T) = R: GoTo i01
End If
Crr(R, 2) = Crr(R, 2) + Brr(i, 3)
i01: Next
With [Summary!A1].Resize(Y, 3)
.EntireColumn.ClearContents
.Value = Crr
End With
Set Z = Nothing: Erase Brr, Crr
End Sub