Excel Dupes

This is not comprehensive or flexible, it's a quick hack that saved me some time. It loops over the first cell of each row and highlights sets that are duplicate values (tip: do an extended sort on the first column before executing). Here you go:


Sub HighlightDupes()
    LastVal = ""
Set sh = ActiveSheet
For Each r In sh.Rows
    
    If LastVal = sh.Cells(r.Row, 1).Value Then
        sh.Cells(r.Row - 1, 1).Interior.Color = RGB(255, 210, 0)
        sh.Cells(r.Row, 1).Interior.Color = RGB(255, 210, 0)
    End If
    
    LastVal = sh.Cells(r.Row, 1).Value
    
    If sh.Cells(r.Row, 1).Value = "" Then
        Exit For
    End If

Next r

End Sub