Excel中高亮显示重复值

分类:代码, 博客 标签:,

Excel中采用统计函数CountIf来对重复值高亮显示,如果需要更改高亮颜色则修改iterCell.Interior.ColorIndex = 6中的颜色值,具体实现代码如下:

'================================
' Excel中高亮显示重复值
'
' http://www.cnhup.com
'================================
Sub Highlight_Duplicates(rngValues As Range)
    Dim iterCell As Range

    For Each iterCell In rngValues
        If WorksheetFunction.CountIf(rngValues, iterCell.Value) > 1 Then
            iterCell.Interior.ColorIndex = 6
        Else
            iterCell.Interior.ColorIndex = 0
        End If
    Next
End Sub


分类:代码, 博客 标签:,

发表评论

You must be logged in to post a comment.