|
gaoch35 发表于 2014-12-2 10:34
如果我想指定两个或多个单元格区域,不是列,比如两个单元格区域为a3:b17和c5:e21,那代码怎么改
楼主按需要改代码
- Sub SC2()
- Application.ScreenUpdating = False
- rng1 = "A3: B17"
- rng2 = "C5: E21"
- rng3 = "A22:E28"
- Union(Range(rng1), Range(rng2), Range(rng3)).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) + Application.CountIf(Range(rng3), 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).Activate
- Do
- Selection.FindNext(After:=ActiveCell).Delete Shift:=xlUp
- s = s - 1
- Loop While s > 1
- End If
- Next
- Application.ScreenUpdating = True
- End Sub
复制代码
|
|