Option Explicit
Sub TEST()
Dim Brr, V&, Y, Z, i&, j%, T$, xR As Range
Set Y = CreateObject("Scripting.Dictionary")
Brr = Range([資料!D2], [資料!A65536].End(3))
For i = 1 To UBound(Brr)
T = Brr(i, 1): V = Brr(i, 4)
Z = Switch(V <= 5000, "5000以下", (V > 5000) * (V <= 10000), "5001~10000", V > 10000, "10000以上")
Y(T & "|" & Z) = Y(T & "|" & Z) + V: Y(T & "|" & Z & "|Qty") = Y(T & "|" & Z & "|Qty") + 1
Next
'=========================================
[統計!B2:G4,統計!B8:G10].ClearContents
Set xR = [統計!A1:G4]: Brr = xR
For i = 2 To UBound(Brr)
For j = 2 To UBound(Brr, 2): Brr(i, j) = Y(Brr(1, j) & "|" & Brr(i, 1)): Next
Next
xR = Brr
'=========================================
Set xR = [統計!A7:G10]: Brr = xR
For i = 2 To UBound(Brr)
For j = 2 To UBound(Brr, 2): Brr(i, j) = Y(Brr(1, j) & "|" & Brr(i, 1) & "|Qty"): Next
Next
xR = Brr
Set Y = Nothing: Set xR = Nothing: Erase Brr
End Sub作者: hcm19522 時間: 2023-6-7 10:14