对于一行中的所有唯一单元格,删除行

时间:2022-06-16 12:42:42

I need to delete the rows for all cells in column "E" that are unique, so I have only "NON-Unique" cells in column i.e Column "E" has only duplicates.

我需要删除列“E”中所有单元格中唯一的行,因此我在列中只有“非唯一”单元格,即“E”列只有重复项。

I have been searching for code to do this but have found very little.

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

Sorry I cant even post a snip-it to start off with.

对不起,我甚至不能发布一个剪辑它开始。

Thanks

1 个解决方案

#1


0  

Give this a try:

尝试一下:

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

#1


0  

Give this a try:

尝试一下:

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