用数据透视表法就你可以,你的意思是A列B列是用来分类的C列相加是吗?数据多时候用数据透视表就可以
可以的。数据量大么
Sub 宏1()
Cells.Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("A1:A3"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("B1:B3"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A1:C3")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
For i = 3 To 1 Step -1
If Cells(i, 1) = Cells(i + 1, 1) Then
If Cells(i, 2) = Cells(i + 1, 2) Then
Cells(i, 3) = Cells(i, 3) + Cells(i + 1, 3)
Rows(i + 1).Select
Selection.Delete Shift:=xlUp
End If
end if
Next i
End Sub
试过了,可以用的