|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 Vicel 于 2014-12-5 13:37 编辑
gaoch35 发表于 2014-12-5 11:24
怎么有两个完全相同的要连续运行两次才能把两个都清空,有三个完全相同的要连续运行三次才能把三个都清空 ...
楼主,说真的,我很怀疑你的理解能力,不知楼主你是怎样操作的
如下图,清空前共有5组完全重复的单元格
选择A1:E39区域后(当然也可以选择重叠的区域),执行29楼的代码2(这里删除了37行,用上38、39行的代码)
- Sub SC()
-
- Dim rng As Range, cell As Range, d As Object, dd As Object, s As Integer, n As Integer, Z As String, T As String
- Set d = CreateObject("scripting.dictionary")
- Set dd = CreateObject("scripting.dictionary")
- Application.ScreenUpdating = False
- s = 0: n = 0
- For Each cell In Selection
- Z = cell.Address(0, 0)
- T = cell.Value
- If Not d.exists(Z) Then
- s = s + 1
- d.Add Z, T
- If T = "" Then
- GoTo 1 '单元格值为空直接往下一单元格
- ElseIf Trim(T) <> "" Then
- If Not dd.exists(T) Then
- dd.Add T, Z
- k = dd.Item(T)
- ElseIf Z <> dd.Item(T) Then
- n = n + 1
- If rng Is Nothing Then
- Set rng = cell
- Else
- Set rng = Union(rng, cell)
- End If
- End If
- Else
- cell.Value = ""
- End If
- Else
- GoTo 1 '单元格为已查询过的,直接往下一单元格
- End If
- 1: Next
- d.RemoveAll
- rng.Select
- Selection.Clear
- MsgBox "共选择了" & s & "个单元格,其中" & n & "个重复单元格已被清空"
- Application.ScreenUpdating = True
-
- End Sub
复制代码 得到下图的结果(完全重复的单元格只保留一个,其余已经清空)
|
|