Matthew said:
I can modify Tony's solution fo you. For the specific range of B10:B500,
you would select the range B10:B500. Note what the active cell is (the
whole range is highlighted but one cell is where the 'cursor' is - where
you would enter information if you were to type something). For this
example, B10 is the active cell. If B10 isn't you would need to change
any lone B10 references to that cell (but not the B10:B500 references).
First conditional format:
=AND(COUNTIF(B10:B500,B10)>1,COUNTIF($B$10:B10,B10)=1)
(use the Format... button to select a 'first occurance of duplicates'
format)
Second conditional format:
=COUNTIF(B10:B500,B10)>1
(use the Format... button to select a 'duplicate occurance' format)
You can refer to my earlier message for a more step-by-step walkthru for
the conditional format steps.
Now, this formatting would not look for duplicates past line 500. Tony's
solution refered to the entire column - so when data is added past line
500 it would be part of the lookup range. (To change to Tony's solution,
change B10:B500 to B:B.)
Finally, if people are pasting data in from other worksheets, this
format will likely be lost as people will copy their formats along with
their values when they copy-paste. People can Edit | Paste Special |
Values(option) to avoid this, but people forget.
I'm putting together a event macro for you that won't have these
limitations.
Matthew
Perhaps not the best event macro, but it has the benefit of working.
You can goto Tools | Macros | Visual Basic Editor to pull up the macro
editor. Then open the Sheet page in the Project Explorer and paste
this in. You can change the line
Const DATA_RANGE = "B10:E500"
to suit you needs.
Good luck,
Matthew
Private Sub Worksheet_Change(ByVal Target As Range)
Const DATA_RANGE = "B10:E500"
Dim rngColumn As Range
Dim rngFound As Range
Dim blnTargetFirst As Boolean
Dim blnMultiplesFound As Boolean
Dim intLastFoundRow
If Target.Cells.Count > 1 Then Exit Sub
If Target.Value = "" Then Exit Sub
If Not Application.Intersect(Target, Range(DATA_RANGE)) Is
Nothing Then
Application.EnableEvents = False
For Each rngColumn In Range(DATA_RANGE).Columns
If Not Application.Intersect(Target, rngColumn) Is
Nothing Then
Set rngFound = rngColumn.Find(Target.Value)
blnTargetFirst = True
Do
If Not rngFound.Address = Target.Address Then
If blnTargetFirst Then
blnTargetFirst = False
rngFound.Interior.Color = RGB(0, 255, 0)
Else
rngFound.Interior.Color = RGB(255, 0, 0)
End If
blnMultiplesFound = True
End If
intLastFoundRow = rngFound.Row
Set rngFound = rngColumn.Find(Target.Value, rngFound)
Loop Until rngFound.Row <= intLastFoundRow
End If
If blnTargetFirst And blnMultiplesFound Then
Target.Interior.Color = RGB(0, 255, 0)
ElseIf blnMultiplesFound Then
Target.Interior.Color = RGB(255, 0, 0)
Else
Target.Interior.Pattern = xlPatternNone
End If
Next
Application.EnableEvents = True
End If
End Sub