|
楼主 |
发表于 2016-3-24 22:09
|
显示全部楼层
Sub addwithdel_1()
Dim a%, b%
For a = Range("A65536").End(xlUp).Row + 1 To 2 Step -1
For b = a - 1 To 2 Step -1
If Cells(a, "B").Value = Cells(b, "B") Then
If Cells(a, "C").Value = Cells(b, "C") Then
Cells(b, "D").Value = Cells(b, "D").Value + Cells(a, "D").Value
Cells(b, "E").Value = Cells(b, "E").Value + Cells(a, "E").Value
Rows(a).Delete shift:=xlUp
End If
End If
Next b
Next a
End Sub
Sub adwithdel_2()
Dim a As Range, b As Range, c%, d%
c = Range("A65536").End(xlUp).Row
d = 2
Set a = Range("A1")
Set b = Range("A1")
For Each a In Range(Cells(d, "B"), Cells(c, "B"))
For Each b In Range(Cells(d + 1, "B"), Cells(c, "B"))
If b.Value = a.Value Then
If Cells(b.Row, "C").Value = Cells(a.Row, "C") Then
Cells(a.Row, "D").Value = Cells(a.Row, "D").Value + Cells(b.Row, "D").Value
Cells(a.Row, "E").Value = Cells(a.Row, "E").Value + Cells(b.Row, "E").Value
Rows(b.Row).Delete shift:=xlUp
End If
End If
Next b
d = d + 1
c = Range("a65536").End(xlUp).Row
Next a
End Sub |
|