就是找到不重复值,并对相同名下的值进行累加:
1 Sub 分类求和() 2 Dim arry(1 To 9, 1 To 2) 3 Set Rng = Cells(Rows.Count, 3).End(xlUp) 4 ''k = Cells.Row 5 'Rng.Select 6 arr = Range([b2], Rng) 7 For i = 1 To Rng.Row - 1 8 For j = 1 To UBound(arry, 1) 9 If arr(i, 1) = arry(j, 1) Then 10 arry(j, 2) = arry(j, 2) + arr(i, 2) 11 GoTo 100: 12 End If 13 Next j 14 k = k + 1 15 arry(k, 1) = arr(i, 1) 16 arry(k, 2) = arr(i, 2) 17 100: 18 Next i 19 [i2].Resize(k, 2) = arry 20 End Sub