答案 0 :(得分:4)
解决方案1-公式:
对于第1条:
=SUMIF($A$8:$A$21,"=Article 1",$B$8:$B$21)
对于第2条:
=SUMIF($A$8:$A$21,"=Article 2",$B$8:$B$21)
解决方案2-数据透视表” ,如Pᴇʜ建议
数据
结果
答案 1 :(得分:2)
答案 2 :(得分:0)
由于这个问题带有一个vba标签,因此脚本字典可以很快速地得出摘要。
Option Explicit
Sub SumArticles()
Dim i As Long, arr As Variant, dic As Object
'set up a dictionary object
Set dic = CreateObject("scripting.dictionary")
'work with Sheet1
With Worksheets("sheet1")
'collect values from worksheet
arr = .Range(.Cells(8, "A"), .Cells(.Rows.Count, "B").End(xlUp)).Value2
'loop through array, summing to dictionary items
For i = LBound(arr, 1) To UBound(arr, 1)
'shorthand overwrite dictionary add method
dic.Item(arr(i, 1)) = dic.Item(arr(i, 1)) + arr(i, 2)
Next i
'put dictionary keys and items back on worksheet
.Cells(8, "E").Resize(dic.Count, 1) = Application.Transpose(dic.keys)
.Cells(8, "F").Resize(dic.Count, 1) = Application.Transpose(dic.items)
End With
End Sub