MS Excel how to create a macro to find duplicates and highlight them?

后端 未结 5 1277
臣服心动
臣服心动 2020-12-22 13:13

How can I create a macro in MS excel to find duplicates in a spreadsheet and highlight it

5条回答
  •  醉梦人生
    2020-12-22 13:45

    Maybe this snippet is useful:

    Public Sub MarkDuplicates()
    Dim iWarnColor As Integer
    Dim rng As Range
    Dim rngCell As Variant
    
    
    Set rng = Range("A1:A200") ' area to check '
    iWarnColor = xlThemeColorAccent2
    
    For Each rngCell In rng.Cells
        vVal = rngCell.Text
        If (WorksheetFunction.CountIf(rng, vVal) = 1) Then
            rngCell.Interior.Pattern = xlNone
        Else
            rngCell.Interior.ColorIndex = iWarnColor
        End If
    Next rngCell
    End Sub
    

提交回复
热议问题