Y
yukon_phil
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
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