請教如統計EXCEL中相同的行?
如下
AA BB CC 25
AA CC BB 15
AA BB DD 24
BB CC AA 14
BB AA DD 25
BB CC FF 25
如果第一列和第二列相同,則第四列相加
轉成如下“
AA BB 49
AA CC 15
BB CC 39
BB AA 25
實現方法是SHEET1中放上一個按扭,把需要的結果轉存到SHEET2或另存也可以!
[解决办法]
最简单的方法就是直接使用数据透视表。
QQ群 48866293 OFFICE应用挖掘
MS OFFICE(ACCESS\EXCE\WORD等应用技术探讨与交流!技术群,请阅群论坛中的《踢人规则》
[解决办法]
'VBA CODESub a() Dim i As Long, L As Long, n As Long, m() As Long, x As Long L = Sheet1.Cells.SpecialCells(xlLastCell).Row ReDim m(L) For i = 1 To L x = Sheet1.Cells(i, 4) For j = i + 1 To Sheet1.Cells.SpecialCells(xlLastCell).Row If Sheet1.Cells(i, 1) = Sheet1.Cells(j, 1) And _ Sheet1.Cells(i, 2) = Sheet1.Cells(j, 2) And _ m(j) <> 1 Then x = x + Sheet1.Cells(j, 4) m(j) = 1 End If Next If m(i) <> 1 Then 'n = n + Sheet2.Cells.SpecialCells(xlLastCell).Row + 1 n = n + 1 Sheet2.Cells(n, 1) = Sheet1.Cells(i, 1) Sheet2.Cells(n, 2) = Sheet1.Cells(i, 2) Sheet2.Cells(n, 3) = x End If Next End Sub