简体   繁体   English

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

[英]For all unique cells in a row, delete rows

I need to delete the rows for all cells in column "E" that are unique, so I have only "NON-Unique" cells in column ie Column "E" has only duplicates. 我需要删除“ E”列中所有单元格的唯一行,因此列中只有“ NON-Unique”单元格,即“ 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 谢谢

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 循环遍历我的行,如果2个单元格包含任何值,则删除行 - Loop trought my rows and delete row if 2 cells contains any value 删除单元格但不删除行 - delete cells but not rows Excel VBA-查找具有值的所有单元格并删除整行(如果存在) - Excel VBA - Find all cells with value and delete the entire row if it exist 如果特定范围内所有基于公式的单元格为0或空白,则删除行 - Delete row if all formula-based cells in a certain range are 0 or blank vba代码在特定列的所有单元格中搜索0(如果找到),然后删除该行 - vba code to search for 0 in all the cells of particular column if found then delete that row 宏可根据条件将不同行中的单元格复制到1行中,并删除剩余的空白/移位单元格 - Macro to copy cells from different rows into 1 row based on a criteria and delete blanks/shift cells left VBA-删除复制数据中最后一行之后的所有行 - VBA - Delete all rows after last row in copied data 删除CSV(Excel)中的所有行(第n行除外) - Delete all rows in CSV(Excel) except each nth row VBA Excel如何删除筛选器空白行(而不是整个行)并向上移动单元格 - VBA Excel How to delete filter blank rows (but not entire row) and shift cells up VBA功能可在工作表的同一行中的不同单元格上输出所有唯一值 - VBA function that outputs all unique values on different cells in the same row in worksheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM