2014-03-24 66 views
0

我需要删除列“E”中所有单元格的行都是唯一的,所以在列中只有“非唯一”单元格列“E”只有重复。对于一行中的所有唯一单元格,删除行

我一直在寻找代码来做到这一点,但发现很少。

对不起,我甚至不能发布剪断它开始。

感谢

+1

我认为这可以帮助你:寻找并只留下副本以电子表格(http://stackoverflow.com/questions/22584617/在电子表格中查找和只留下重复项/ 22584707#22584707) –

+0

你试过DISTINCT运算符吗? –

回答

0

这给一试:

Sub RemoveUniques() 
    Dim E As Range, rDel As Range, r As Range, N As Long 
    N = Cells(Rows.Count, "E").End(xlUp).Row 
    Set E = Range("E1:E" & N) 
    Dim wf As WorksheetFunction 
    Set wf = Application.WorksheetFunction 
    Set rDel = Nothing 
    For Each r In E 
     v = r.Value 
     If wf.CountIf(E, v) = 1 Then 
      If rDel Is Nothing Then 
       Set rDel = r 
      Else 
       Set rDel = Union(rDel, r) 
      End If 
     End If 
    Next r 

    If Not rDel Is Nothing Then 
     rDel.EntireRow.Delete 
    End If 
End Sub 
相关问题