sn152
Member
Hi All,
I am trying to restrict the users from pasting data on Data validated cells. But it is not working.
I am using the below code. This actually works. But the problem is when the users copy pastes data, it will show a pop up message with OK button. But even after clicking on OK button, the pop up message is not going.
Please note that the data validation is on a range of cells(Range A2: A500, C2:C500, D2:D500 etc.)
Kindly help me on this. I am using Excel 2013. Thanks in advance!
I am trying to restrict the users from pasting data on Data validated cells. But it is not working.
I am using the below code. This actually works. But the problem is when the users copy pastes data, it will show a pop up message with OK button. But even after clicking on OK button, the pop up message is not going.
Please note that the data validation is on a range of cells(Range A2: A500, C2:C500, D2:D500 etc.)
Kindly help me on this. I am using Excel 2013. Thanks in advance!
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Does the validation range still have validation?
If HasValidation(Range("ValidationRange")) Then
Exit Sub
Else
Application.Undo
MsgBox "Your last operation was canceled." & _
"It would have deleted data validation rules.", vbCritical
End If
End Sub
Private Function HasValidation(r) As Boolean
' Returns True if every cell in Range r uses Data Validation
On Error Resume Next
x = r.Validation.Type
If Err.Number = 0 Then HasValidation = True Else HasValidation = False
End Function
Last edited: