VBA: 如何给重复的行上色?

VBA: How to color a duplicate row?

我是 vba 的新手,我需要帮助为重复的行着色,而不仅仅是为这样做的单元格着色,任何可以在这里帮助我的人。

Sub FindDuplicate()

Dim cel As Variant
Dim myrng As Range
Dim clr As Long

Set myrng = Range("S2:S" & Range("S65536").End(xlUp).row)
myrng.Interior.ColorIndex = xlNone
clr = 3

For Each cel In myrng
    If Application.WorksheetFunction.CountIf(myrng, cel) > 1 Then
        If WorksheetFunction.CountIf(Range("S2:S" & cel.row), cel) = 1 Then
            cel.Interior.ColorIndex = 3
        Else
            cel.Interior.ColorIndex = myrng.Cells(WorksheetFunction.Match(cel.Value, myrng, False), 1).Interior.ColorIndex
        End If
    End If
Next

End Sub

在您的代码中,更改

cel.Interior.ColorIndex = 3

Rows(cel.Row).Interior.ColorIndex = 3

我用jeanno的回答解决了,谢谢

我补充了:

Rows(cel.row).Interior.ColorIndex = 3
        Else
            Rows(cel.row).Interior.ColorIndex = myrng.Cells(WorksheetFunction.Match(cel.Value, myrng, False), 1).Interior.ColorIndex