你的意思是,第1列+第2列=第1列+第2列,或者,第1列+第2列=第2列+第1列,当作是重复的情况吧?
这个操作很麻烦,我试了一下要实现这个没几十行代码做不了,没试了。
不过,我们是不是可以这样做,第3列,第4列,第5列的数据是一样的,再来检查第1列和第2列是否重复? 代码如下,你试一下,不行你加我QQ 39482788,我不常上论坛。
Sub delete()
Dim i As Integer
Sheets("sheet1").Select
lastrow = [A65536].End(xlUp).Row
Columns("A:E").Select
Selection.Sort Key1:=Range("C1"), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
:=xlPinYin, DataOption1:=xlSortNormal
For i = 1 To lastrow
If Cells(i, 3) = Cells(i + 1, 3) And Cells(i, 4) = Cells(i + 1, 4) And Cells(i, 5) = Cells(i + 1, 5) Then
If Cells(i, 1) = Cells(i + 1, 1) And Cells(i, 2) = Cells(i + 1, 2) Then
Range(Cells(i + 1, 1), Cells(i + 1, 5)).Select
Selection.delete '如果数据量非常大,采用.delete执行效率可能会比较低,那你就考虑用.clearcontents吧
Else
If Cells(i, 1) = Cells(i + 1, 2) And Cells(i, 2) = Cells(i + 1, 1) Then
Range(Cells(i + 1, 1), Cells(i + 1, 5)).Select
Selection.delete
End If
End If
End If
Next i
End Sub
这个操作很麻烦,我试了一下要实现这个没几十行代码做不了,没试了。
不过,我们是不是可以这样做,第3列,第4列,第5列的数据是一样的,再来检查第1列和第2列是否重复? 代码如下,你试一下,不行你加我QQ 39482788,我不常上论坛。
Sub delete()
Dim i As Integer
Sheets("sheet1").Select
lastrow = [A65536].End(xlUp).Row
Columns("A:E").Select
Selection.Sort Key1:=Range("C1"), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
:=xlPinYin, DataOption1:=xlSortNormal
For i = 1 To lastrow
If Cells(i, 3) = Cells(i + 1, 3) And Cells(i, 4) = Cells(i + 1, 4) And Cells(i, 5) = Cells(i + 1, 5) Then
If Cells(i, 1) = Cells(i + 1, 1) And Cells(i, 2) = Cells(i + 1, 2) Then
Range(Cells(i + 1, 1), Cells(i + 1, 5)).Select
Selection.delete '如果数据量非常大,采用.delete执行效率可能会比较低,那你就考虑用.clearcontents吧
Else
If Cells(i, 1) = Cells(i + 1, 2) And Cells(i, 2) = Cells(i + 1, 1) Then
Range(Cells(i + 1, 1), Cells(i + 1, 5)).Select
Selection.delete
End If
End If
End If
Next i
End Sub