Hi,
I have this code
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
'Does the validation range still have validation?
If HasValidation(Range("E2:F32")) Then
Exit Sub
Else
Application.Undo
MsgBox "Your last operation was canceled." & _
"It would have deleted data validation rules.", vbCritical
End If
Application.EnableEvents = True
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
Which stops deleting and it also stops pasting it in any cell.
But when I choose anything from the list it gives me an error.
please help me out with this
I have this code
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
'Does the validation range still have validation?
If HasValidation(Range("E2:F32")) Then
Exit Sub
Else
Application.Undo
MsgBox "Your last operation was canceled." & _
"It would have deleted data validation rules.", vbCritical
End If
Application.EnableEvents = True
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
Which stops deleting and it also stops pasting it in any cell.
But when I choose anything from the list it gives me an error.
please help me out with this