'你这输出表格设计的有问题,这只是一个转置的表格
Option Explicit
Sub abc()
Dim a, i, m, n, p, d(1)
a = [a1].CurrentRegion.Resize(, 4).Value
ReDim b(UBound(a), 30) '最多支持30个种类
For i = 0 To UBound(d)
Set d(i) = CreateObject("scripting.dictionary")
Next
For i = 2 To UBound(a)
If Len(a(i, 1)) Then p = i
If Not d(0).exists(a(p, 1)) Then m = m + 1: d(0)(a(p, 1)) = m: b(m, 0) = a(p, 1)
If Not d(1).exists(a(i, 2)) Then n = n + 1: d(1)(a(i, 2)) = n: b(0, n) = a(i, 2)
b(d(0)(a(p, 1)), d(1)(a(i, 2))) = b(d(0)(a(p, 1)), d(1)(a(i, 2))) + a(i, 3)
Next
[f1].Resize(m + 1, UBound(b, 2) + 1) = b
End Sub