John Walkenbach - Ensuring that Data Validation is Not Deleted
Perhaps:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target,Range("ValidationRange")) is nothing then exit sub
If Application.CutcopyMode = True then
Application.CutCopyMode = False
MsgBox "Your can't paste to this Range." & _
"It would have deleted data validation rules.", vbCritical
End If
End Sub
--
Regards,
Tom Ogilvy
"al007" wrote in message
oups.com...
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
The macro do not work if copied cells already contain validation -
specially if my range is a column & user will copy cells from the
column.
Can anybody help
|