Hi
How do i adjust the Macro code so that it only find duplicate entries from selected sheet and not the whole workbook
I have 12 sheets named January through to December that need to be checked for duplicate entries and 3 other sheets that i do not want checked for duplicate entries.
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim ws As Worksheet, EvalRange As Range
Set EvalRange = Range("A3:A500")
If Intersect(Target, EvalRange) Is Nothing Or Target.Cells.Count > 1 Then Exit Sub
If IsEmpty(Target) Then Exit Sub
If WorksheetFunction.CountIf(EvalRange, Target.Value) > 1 Then
MsgBox Target.Value & " already exists on this sheet."
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
For Each ws In Worksheets
With ws
If .Name <> Target.Parent.Name Then
If WorksheetFunction.CountIf(Sheets(.Name).Range("A1:A500"), Target.Value) > 0 Then
MsgBox Target.Value & " already exists on the sheet named " & .Name & ".", _
16, "No duplicates allowed in " & EvalRange.Address(0, 0) & "."
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
Exit For
End If
End If
End With
Next ws
End Sub
Bookmarks