Pages

Sunday, February 7, 2010

How do I highlight duplicate rows in Excel without deleting them?

There is a Delete Duplicates function in Excel that makes it very easy to delete any duplicate data in your spreadsheet. However, sometimes you may not want to delete that data, you just want to know that there are duplicates. One way of doing this is with a simple macro. To highlight and draw attention to duplicates in a Microsoft Excel spreadsheet with a bold red color create this macro (alt+F11 opens the macro editor):

Sub DupsinRed()
Application.ScreenUpdating = False
Rng = Selection.Rows.Count
For i = Rng To 1 Step -1
myCheck = ActiveCell
ActiveCell.Offset(1, 0).Select
For j = 1 To i
If ActiveCell = myCheck Then
Selection.Font.Bold = True
Selection.Font.ColorIndex = 3
End If
ActiveCell.Offset(1, 0).Select
Next j
ActiveCell.Offset(-i, 0).Select
Next i
Application.ScreenUpdating = True
End Sub

The statement "Application.ScreenUpdating = False" prevents the screen from updating to ensure the macro runs faster and the screen will not flicker. Don't forget to set it back to "True".

11 comments:

  1. Why not? Are you getting an error message?

    ReplyDelete
  2. no you don't have to use macro. first block the cells where you want to find out the duplicate values. and then from column Styles in "Home", you select Conditional Formatting, then choose Highlight Cells Rules --> Duplicate values. there you go :)

    ReplyDelete
    Replies
    1. The problem with this is that it will only highlight the duplicate cells, not the entire row

      Delete
    2. This is exactly what I was needing to do. And when I was done I just did a control Z to remove the highlights. Thanks so much Vira Av for this easy alternate method.

      Delete
    3. What a great tip!

      Delete
  3. No problem! Glad I could help. Sign up for our email newsletter for more tips.

    ReplyDelete
  4. Is there a way to undo the Conditional formatting when you are done?

    ReplyDelete
  5. This is really very nice information you share here. Delete duplicate function is really good to used for all excel users to highlight all duplicate data in excel spreadsheet without delete them. This function works really good and makes easy way to delete all duplicate data in excel spreadsheet.

    excel trainingin melbourne

    ReplyDelete

I'd love to hear from you!
-Nick