HI Sixth sense
I think I have it solved.
In my worksheet change event I set the target to just A4
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$4" Then
Call checkRepeat
End If
End Sub
Then I created a new macro witht he check for repeat code
Now it doesnt fire off when in a different cell.
Heres my macro code to do the check and allow repeat if cancel is selected
Sub checkRepeat()
Dim ws As Worksheet, wkb As Workbook, EvalRange As Range
Set wkb = ActiveWorkbook
Set ws = wkb.Worksheets("Orders")
Set Target = Range("a4")
Target.NumberFormat = "0000"
'Set the range where I want to prevent duplicate entries.
Set EvalRange = Range("a4:a10000")
MsgBox Target
'If the cell where value was entered is not in the defined range, if the value pasted is larger than a single cell,
'or if no value was entered in the cell, then exit the macro.
If Intersect(Target, EvalRange) Is Nothing Or Target.Cells.Count > 1 Then Exit Sub
If IsEmpty(Target) Then Exit Sub
'If the value entered already exists in the defined range on the current worksheet, throw an
'error message and undo the entry.
If WorksheetFunction.CountIf(EvalRange, Target.Value) > 1 Then
If MsgBox(Target.Value & " has already been used." & vbCr & "Do you want to use the same number (cancel) or enter a new one (retry)?", vbRetryCancel) = vbRetry Then
Application.EnableEvents = False
'
Application.EnableEvents = True
Range("A4").Value = ""
Range("A4").Select
End If
End If
End Sub
The old fogey
Bookmarks