Sub 分類統計()
Dim xD, xR As Range, Arr, Brr, i&, j%, Jm&, T, N&, C&(1 To 4)
Sheets("統計").UsedRange.Offset(1, 0).EntireRow.Delete
Arr = Range([資料!A2], [資料!A65536].End(xlUp)(1, 5))
ReDim Brr(1 To UBound(Arr), 1 To 12)
Set xD = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(Arr)
T = 0
For j = 1 To 4
T = T * IIf(j = 4, 100, 10) + Arr(i, j + 1)
Jm = xD(T)
If Jm = 0 Then C(j) = C(j) + 1: Jm = C(j): xD(T) = Jm
If Jm > N Then N = Jm
Brr(Jm, 12 - j * 3 + 1) = T
Brr(Jm, 12 - j * 3 + 2) = Brr(Jm, 12 - j * 3 + 2) + Arr(i, 1)
Brr(Jm, 12 - j * 3 + 3) = Brr(Jm, 12 - j * 3 + 3) + 1
Next j: Next i
Set xR = [統計!A2]
xR.Resize(N, 12) = Brr
For j = 1 To 4
xR.Resize(N, 3).Sort Key1:=xR, Order1:=xlAscending, Header:=xlNo
Set xR = xR(1, 4)
Next j
End Sub