Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim RowRng As Range
Dim ColRng As Range
'Dont apply code if it is a change to more than just a single cell
If Target.Cells.Count > 1 Then Exit Sub
'determine changed cell ,'Target', is within sensible range of interest
If Not Intersect(Target, Range("B3:AZ15")) Is Nothing Then '<< ????? Edit range to suit
Set RowRng = Range(Target.EntireRow.Address) ' set to Target row
Set ColRng = Range(Target.EntireColumn.Address) ' set to Target Column
' check for duplicate entry in row or column
Debug.Print Application.WorksheetFunction.CountIf(RowRng, Target) > 1 Or Application.WorksheetFunction.CountIf(ColRng, Target) > 1
If Application.WorksheetFunction.CountIf(RowRng, Target) > 1 Or Application.WorksheetFunction.CountIf(ColRng, Target) > 1 Then
Target.Interior.ColorIndex = 3 'if duplicate, hidhlight CELL red
'display message andawait response
Resp = MsgBox("Do you wish to keep this duplicate enty?", vbYesNo, "DUPLICATE ENTRY!!!")
If Not Resp = vbYes Then 'If response is No then
Application.EnableEvents = False 'Disable event handling otherwise this event will call itself again
Target.ClearContents 'clear the Target entry
Target.Interior.ColorIndex = xlColorIndexNone 'clear the highlight
Target.Select 're-select the Target cell forpossible re-entry
Application.EnableEvents = True 're-establish event handling
End If
'If response is Yes then do nothing and the duplicate cell will remain highlighted
End If
End If
End Sub