Auto highlight duplicates

Ignition1

New Member
Joined
Feb 22, 2011
Messages
49
Hi all

Is there a way (well...there is always a way) for Excel to automatically highlight duplicates once something has been typed.

I.e. In Column A is a list of names.

Dave
John
Sara

As I enter new names, if I put Dave again then that cell is highlighted in yellow. Or even better if the name matches a few phrases in a cell previous to it - then highlight in yellow.

I'm learning VBA but I know the basics - this feels like a task for VBA.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Try this: right click the sheet tab, select View Code and paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
    If WorksheetFunction.CountIf(Columns("A"), Target.Value) > 1 Then Target.Interior.ColorIndex = 6
End If
End Sub
 
Upvote 0
Hi all

Is there a way (well...there is always a way) for Excel to automatically highlight duplicates once something has been typed.

I.e. In Column A is a list of names.

Dave
John
Sara

As I enter new names, if I put Dave again then that cell is highlighted in yellow. Or even better if the name matches a few phrases in a cell previous to it - then highlight in yellow.

I'm learning VBA but I know the basics - this feels like a task for VBA.
You can use conditional formatting to do this.

Want to do it that way?
 
Upvote 0
Perfect! Thanks VoG - I need to study that code and figure out how/why that worked.

Conditional Formatting would have also done the trick (though I wasn't sure if it ran automatically as I added new names or if I had to run formatting again).
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top