View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
al007 al007 is offline
external usenet poster
 
Posts: 118
Default John Walkenbach - Ensuring that Data Validation is Not Deleted

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