|
发表于 2012-2-26 17:23
|
显示全部楼层
本楼为最佳答案
lhj323323 发表于 2012-2-26 15:35
.RemoveDuplicates Array(1, 3), xlNo
对象不支持该属性和方法
用这个 先排序后删除的 可以看到效果
- Sub 排序后删除()
- Dim Hx As Long, Lx As Integer
- Dim Arr As Variant
- Dim Sh As Worksheet
- Dim D As Object
- Dim S As String
- Set Sh = Sheets("数据")
- Set D = CreateObject("Scripting.dictionary")
- Application.ScreenUpdating = False
- With Sh
- Hx = .Range("A65536").End(xlUp).Row
- Lx = .Range("IV2").End(xlToLeft).Column
- With .Range(.Cells(3, "A"), .Cells(Hx, Lx))
- Crr = .Value
-
- .Sort Sh.Range("A3"), 1, Sh.Range("C3"), , 1
- Hx = 0: Lx = 0
- '先排序,然后再删除重复项
- Arr = .Value
- For X = 1 To UBound(Arr)
- S = Arr(X, 1) & " " & Arr(X, 3)
- If D.Exists(S) Then
- Hx = X + 2 - Lx
- Sh.Rows(Hx).Delete
- Lx = Lx + 1
- Else
- D.Add (S), ""
- End If
- Next
- If Lx > 0 Then MsgBox "本次共计删除 " & Lx & " 条重复信息", , "完成"
- .Value = Crr
- End With
- End With
- Application.ScreenUpdating = True
- End Sub
复制代码
这个直接删除的
- Sub 直接删除()
- Dim Hx As Long, Lx As Integer
- Dim Arr As Variant
- Dim Sh As Worksheet
- Dim D As Object
- Dim S As String
- Set Sh = Sheets("数据")
- Set D = CreateObject("Scripting.dictionary")
- Application.ScreenUpdating = False
- With Sh
- Hx = .Range("A65536").End(xlUp).Row
- Arr = .Range("A3:C" & Hx)
- Hx = 0: Lx = 0
- For X = 1 To UBound(Arr)
- S = Arr(X, 1) & " " & Arr(X, 3)
- If D.Exists(S) Then
- Hx = X + 2 - Lx
- .Rows(Hx).Delete
- Lx = Lx + 1
- Else
- D.Add (S), ""
- End If
- Next
- If Lx > 0 Then MsgBox "本次共计删除 " & Lx & " 条重复信息", , "完成"
- End With
- End With
- Application.ScreenUpdating = True
- End Sub
复制代码
|
|