HI All,
I tried the below code to prevent Copy pasting data to Data validation. It works if I try in a single column. My challenge is that I have data validation in 6 to 7 columns which vaies from Col. C to X. I cant able to prevent those using the below code from copy paste. Requiring your experts help
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
Regards,
Vivek T
Moderator's Edit: Use code tags when posting code. To do so in future, select your code and click on the # icon at the top of your post window.
Bookmarks