|
代码如下,楼主按需要再改进改进吧
- Sub SC2() '删除两列所有重复单元格(可以是连续两列,也可以是不连续两列)
- Application.ScreenUpdating = False
- C1 = "A"
- C2 = "B"
- n1 = Cells(Rows.Count, C1).End(xlUp).Row
- n2 = Cells(Rows.Count, C2).End(xlUp).Row
- rng1 = C1 & "1:" & C1 & n1
- rng2 = C2 & "1:" & C2 & n2
- Union(Range(rng1), Range(rng2)).Select
- For Each cell In Selection
- s = 0
- T = cell.Value
- If T <> "" And Trim(T) <> "" Then
- s = Application.CountIf(Range(rng1), T) + Application.CountIf(Range(rng2), T)
- End If
- If s > 1 Then
- Selection.Find(What:=T, After:=ActiveCell, LookIn _
- :=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
- xlNext, MatchCase:=False, SearchFormat:=False).Delete
- Do
- Selection.FindNext(After:=ActiveCell).Delete
- s = s - 1
- Loop While s > 1
- End If
- Next
- Application.ScreenUpdating = True
- End Sub
- Sub SC() '删除连续区域(一列或多列连续)所有重复单元格
- Application.ScreenUpdating = False
- For Each cell In Selection
- s = 0
- T = cell.Value
- If T <> "" And Trim(T) <> "" Then
- s = Application.CountIf(Selection, T)
- End If
- If s > 1 Then
- Selection.Find(What:=T, After:=ActiveCell, LookIn _
- :=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
- xlNext, MatchCase:=False, SearchFormat:=False).Delete
- Do
- Selection.FindNext(After:=ActiveCell).Delete
- s = s - 1
- Loop While s > 1
- End If
- Next
- Application.ScreenUpdating = True
- End Sub
复制代码
删除重复.rar
(6.97 KB, 下载次数: 19)
|
|