我有一个包含3列A,B,C的数据集.A和B以及标签(例如产品类型和城市),C列作为数字数据。
我已经使用以下内容对C:
进行组合和求和A或B.Sub combineandsum1()
'Update 20130829
Dim WorkRng As Range
Dim Dic As Variant
Dim arr As Variant
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Set Dic = CreateObject("Scripting.Dictionary")
arr = WorkRng.Value
For i = 1 To UBound(arr, 1)
Dic(arr(i, 1)) = Dic(arr(i, 1)) + arr(i, 2)
Next
Application.ScreenUpdating = False
WorkRng.ClearContents
WorkRng.Range("A1").Resize(Dic.Count, 1) = Application.WorksheetFunction.Transpose(Dic.keys)
WorkRng.Range("B1").Resize(Dic.Count, 1) = Application.WorksheetFunction.Transpose(Dic.items)
Application.ScreenUpdating = True
End Sub
但这仅适用于单一标准。如何更改此宏,使其显示为:
如果A在A列中是重复的,并且B在B列中是重复,则组合并总和C.
在这里有一个真正的脑力,可以使用帮助。谢谢!