I'm trying to verify a range of cells from M31:M41 and if the cells are grey and a user enters in information by mistake, then a message box appears and then the last action is undone. Here's my code so far
Set rng = ThisWorkbook.Sheets("Edit Entry").Range("M31:M41")
For each cell in rng
If cell.interior.Colorindex = 15 then
If Not Intersect(Target, Range("M31:M41")) Is Nothing then
Msgbox "NOT AN EDITABLE FIELD.", vbCritical + vbOkOnly, "NO DATA ENTRY"
With Application
.EnableEvents = False
.Undo
.EnableEvents = True
End With
End If
End If
Next Cell
The issue, is that it works how I want it to but it gives me the error
Run-Time error '1004': Method 'Undo' of object' _Application' Failed.
Any ideas on how to achieve this without any coding issues?