資料不多, 可用這個:
Sub AAA()
Dim Clmn As Range
Set Clmn = [工作表2!K2].Resize([工作表2!B65536].End(xlUp).Row - 1)
Clmn = "=B2&C2"
With [工作表1!C2].Resize([工作表1!A65536].End(xlUp).Row - 1, 3)
.Formula = "=SUMIF(工作表2!$K:$K,$A2&C$1,工作表2!$E:$E)"
.Value = .Value
.Replace 0, "", Lookat:=xlWhole
End With
Clmn.ClearContents
End Sub
'================================
資料很多, 用這個:
Dim xD, Arr, Brr, i&, j&, T$
Set xD = CreateObject("Scripting.Dictionary")
Arr = Range([工作表2!E1], [工作表2!B65536].End(xlUp))
For i = 2 To UBound(Arr)
T = Arr(i, 1) & Arr(i, 2)
xD(T) = xD(T) + Arr(i, 4)
Next i
'----------------------------
Arr = Range([工作表1!E1], [工作表1!A65536].End(xlUp))
ReDim Brr(1 To UBound(Arr) - 1, 1 To 3)
For i = 2 To UBound(Arr)
For j = 1 To 3
T = Arr(i, 1) & Arr(1, j + 2)
Brr(i - 1, j) = xD(T)
Next j
Next i
'----------------------------
[工作表1!C2].Resize(UBound(Arr) - 1, 3).Value = Brr
End Sub