22079.html
and think about using Data Validation.
Hi Tom,
Here's another simple solution: just put the following code into the worksheet's event code module (right-click on worksheet tab, select View Code..., past code in code pane).
Private Sub Worksheet_Change(ByVal Target As Range)
Dim LastRow As Integer
If Target.Column = 1 Then
If Not IsEmpty(Target.Value) Then
LastRow = Cells(32767, Target.Column).End(xlUp).Row
For i = 1 To LastRow
If i <> Target.Row Then
If Cells(i, Target.Column).Value = Target.Value Then
MsgBox Target.Value & " already exists.", vbExclamation
Target.Value = Empty
Exit For
End If
End If
Next i
End If
End If
End Sub
This example just protects against duplicates entered in column 1, but if you want to protect all columns, simply delete the If Target.Column = 1 Then ... End If. Perhaps you can see how to protect any other column or combination of columns from this example.
Enjoy.
Damon
Re: See...Mark, one more please.
Mark,
Thanks for the advice. It is almost working. I've played with the formula and can't get it perfect. My columns are only A thru H and I'm trying to find the duplicate numbers in column A only. It is doing so but it is only highlighting a some numbers that are not duplicates. Can you offer any other advice please?
Thanks again,
Tom
Did you decide to use Conditional Formatting rather than Validation? [nt]
I'm using conditional but am willing to use whatever works.
Re: I'm using conditional but am willing to use whatever works.
1. Select column A by click on the column header
button.
2. Choose the Format | Conditional Format... menu
command.
3. For Condition1 choose "Formula Is" from the
drop down list.
4. Enter =COUNTIF(A:A,A1)>1 into the Condition1
field.
5. Pick your format after pressing the [ Format... ]
button.
6. Press [ OK ].
That should do it!!!
Thanks Mark, it worked perfect. I really appreciate your help.