View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
yukon_phil yukon_phil is offline
external usenet poster
 
Posts: 25
Default Duplicate Value warning

Thanks for your input, but the code I received from Kostis worked perfectly.

"Tom Hutchins" wrote:

How about this instead?

Private Sub Worksheet_Change(ByVal Target As Range)
If Application.WorksheetFunction.CountIf(Columns(Targ et.Column),
Target.Value) 1 Then
MsgBox "Duplicate entry"
End If
End Sub

Hope this helps,

Hutch

"yukon_phil" wrote:

I have used the following code to give me a warning of duplicated values in a
column, at least I thought it should do this. It does in fact give me the
warning in the column BUT it give me the warning if in the same row and this
is permitted.

How do I get the code correct so it just gives me the warning for the column
values and not the row? Thanks

Private Sub Worksheet_Change(ByVal Target As Range)
'Adjust next constant to your own needs
Const myColumn As String = "B:AF"
Dim rng As Range
Dim Found As Range

Set rng = UsedRange.Columns(myColumn)
If Intersect(Target, rng) Is Nothing _
Or Target.Value = "" _
Then Exit Sub
Set Found = rng.Find(Target.Value)
If Found.Address < Target.Address Then
Target.Select
MsgBox ("Duplicate code")
End If
End Sub