I am trying to prevent users from pasting into data validation field. I got the macro from http://j-walk.com/ss/excel/tips/tip98.htm which is working only for one column. When I select multiple columns which have diff data validations, its not working. Either its restricting the paste across all cells in the sheet(Not in selected range "ComValRngCom") or its allowing in all cells. Following is the code. Pls help.
Private Sub Worksheet_Change(ByVal Target As Range)
'Does the validation range still have validation?
Application.EnableEvents = False
If HasValidation(Range("ComValRngCom")) And HasValidation(Range("ComValRngCntry")) And HasValidation(Range("ComValRngFType")) 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
Bookmarks