Use excel formulas instead of vba.
Fomula for D2:
=IFERROR(INDEX($A$3:$A$7, MATCH(0,COUNTIF($D$1:D1, $A$3:$A$7), 0)),"")
and hit CTR+SHIFT+ENTER
Then use sumif in E2:
=SUMIF($A$2:$A$7, D2, $B$2:$B$7)
Drop the cell down.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…