Showing posts with label highlight duplicate entries in excel. Show all posts
Showing posts with label highlight duplicate entries in excel. Show all posts

Thursday, 25 August 2011

Highlight Duplicate Entry in Excel

You may have to highlight duplicate entries in the excel and you may think it is very difficult to do. We have a solution for it. You need to just copy the below code and it to the excel.

In order to add the code to excel, please follow the steps given below:
1. Open the Excel file.
2. Right click on the page name.
3. Click on the 'View code' option.
4. Paste the following code and save.

Sub FindDups ()
'
' NOTE: You must select the first cell in the column and
' make sure that the column is sorted before running this macro
'
ScreenUpdating = False
FirstItem = ActiveCell.Value
SecondItem = ActiveCell.Offset(1, 0).Value
Offsetcount = 1
Do While ActiveCell <> ""
If FirstItem = SecondItem Then
ActiveCell.Offset(Offsetcount,0).Interior.Color = RGB(255,0,0)
Offsetcount = Offsetcount + 1
SecondItem = ActiveCell.Offset(Offsetcount, 0).Value
Else
ActiveCell.Offset(Offsetcount, 0).Select
FirstItem = ActiveCell.Value
SecondItem = ActiveCell.Offset(1,0).Value
Offsetcount = 1
End If
Loop
ScreenUpdating = True
End Sub
.



5. Sort the column using 'Sort' option. 
6. Go to the macros and click on the 'Run' button.
7. Duplicate entry will be shown in red.