删除列上的重复项而不删除整个行

时间:2019-11-21 02:27:49

标签: excel vba

enter image description here

我要删除同一列上的重复数据,而不删除数据所在的整行,因此data> delete dups将无法解决此问题

单元格中的数据,而不是整个行中的数据,删除公仔时我想将这些单元格留空,为什么不希望整个行都被删除?因为该列旁边的列也有数据,所以删除整行不是

1 个答案:

答案 0 :(得分:1)

这是为您提供的示例代码,

Sub RemoveDuplicates()
    Dim rngData As Range
    Dim iCounter As Integer

'   Please set your range here
    Set rngData = Range("A1:A1000")
 
    For Each cCell In rngData
        If Not (IsEmpty(cCell.Value) Or Trim(cCell.Value) = "") Then
            For iCounter = cCell.Row + 1 To rngData.Rows.Count
                If cCell.Value = rngData(iCounter).Value Then rngData(iCounter).Value = ""
            Next
        End If
    Next

End Sub

相关问题