I have viewed similar posts on the internet but none have worked for me
I have an excel sheet with data validation applied to multiple columns. Data validation prevents from entering an incorrect value when typed into the cells but when I copy any other value from another excel workbook and paste it in the cells, it overrides the data validation. I have found the below code but it only applies when I copy and paste data from the same excel sheet. Can someone please help me with the code for applying data validation to multiple columns upon copy paste from another excel workbook. Thanks.
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
Bookmarks