I have (5) cells containing Data Validation:
B2, B3, B5, B7 & B8 on Sheet 'ADD NEW'
I have a Named Range (ValidationRange) refering to the non-contiguous range of cells containing Data Validation:
ValidationRange =('ADD NEW!$B$2,'ADD NEW!$B$3,'ADD NEW!$B$5,'ADD NEW!$B$7,'ADD NEW!$B$8)
Each Data Validation refers to a Dynamic Named Range
Example B2 = OFFSET('Validation Lists'!$A$2,0,0,COUNTA('Validation Lists'!$A:$A),1)
on the ADD NEW sheet I have this code from
http://www.j-walk.com/ss/excel/tips/tip98.htm
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
Whether you attempt to type data into ANY cell (with Data Val or without), or select an allowed item from the Data Validation List, it always returns the Message.
Clicking OK just brings the message back again and again.
The only way out is to End the Excel Task from the Task Manager.
What am I doing wrong?
PS. I don't particularily care how I insure the Data Validation can't be removed, as long as it can't be.
I've also tried some other ways using
If Union(cell,ValRange).Address
But can't figure that out either.
Thanks
Bookmarks