2003 - Highlight duplicates, but leave one alone

samboytor

New Member
Joined
Jun 21, 2011
Messages
10
I'm looking for a way to highlight duplicate entries but I want to leave one un-highlighted. For example: if I have 5 of the same entry, 4 are highlighted.
 
The formula I have stated will work column wise. All you need to do is copy down the formatting to the bottom most cell. There is no reason why it won't work. It will not highlight across column cells. See below:
Excel Workbook
A
11
21
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A11. / Formula is =COUNTIF($A$1:A1,A1)>1Abc
A21. / Formula is =COUNTIF($A$1:A2,A2)>1Abc
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I think taurean and myself have (incorrectly) interpreted your problem differently to Robert.

How are you entering the data to the sheet? Typing it, formula results, copy and paste, or something else?

Is there any consistancy to the direction in which the data is entered or the number of rows / columns used.

I ask because the code Robert has given you is ideal for doing an entire range, but when you add another entry to that range it would have to re-evaluate the entire range again, other methods could do it per cell as data is added / changed.
 
Last edited:
Upvote 0
I am typing the data in and it is text.

Example: Form 201, PR-0011, WI8.3.0-01

No, there is no consistancy (data is entered down columns and across rows). The number of rows and columns is undetermined.
 
Upvote 0
See if this works for you,

Entering data in say D25 would compare that entry to all data in columns A:C and entries in D1:D24, but would miss D26:Dxx and columns E:xyz.

This would allow you to check each entry as you go, without the delay you would get from Roberts code if you had a lot to process.

As a "double check" clause, I've included a call to Roberts code from mine (so you will need to keep that code in the module), a count of multiple changes will execute Roberts code instead of mine, a quick and easy way to trigger this is to copy 2 cells and paste them over themselves. (i.e. Shift + any cursor key, Ctrl c, Ctrl v), so a fairly quick action.

This code needs to be in the worksheet module, (right click the sheet tab, then view code)

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then
    HighlightDups
Else
    If Cells.Find(What:=Target.Value, After:=[A1], LookIn:=xlValues, LookAt:= _
        xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False).Address = Target.Address Then
        Target.Interior.Pattern = xlNone
    Else: Target.Interior.Color = RGB(0, 255, 0)
    End If
End If
End Sub
 
Upvote 0
That sounds like what I'm looking for, but I don't think I'm using your code properly (I'm not seeing any different results).

Do I put your code in the same module as Robert's code? If so, which one goes first?
 
Upvote 0
No, Robert's code needs to stay in the regualr module, my code needs to go into the module that is specific to the worksheet.

Right click the sheet tab in excel (i.e. the bit at the bottom that says "Sheet1" or whatever you sheet is called), then click "View code", that will take you to the correct place.

If that doesn't work try running this code in a regular module to make sure event handling is enabled.

Code:
Sub Enable()
    Application.EnableEvents = True
End Sub
 
Last edited:
Upvote 0
Nice. That works for me.

I hate to be picky, but why doesn't the hilighting hold true for A1 & A2, and sometimes B1?
 
Upvote 0
You could use this condition to highlight duplicates in a column, leaving the first one not highlited.

=(MATCH(A1, A:A,0)<>ROW(A1))
 
Upvote 0
You could use this condition to highlight duplicates in a column, leaving the first one not highlited.

=(MATCH(A1, A:A,0)<>ROW(A1))

I think you made the same interpretation error as I did earlier mike, the record needs to be compared to multiple rows and columns, not just 1.

I couldn't see any way of doing that without arrays. :confused:
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,706
Members
452,939
Latest member
WCrawford

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