Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Range Validation property not working w/ Protected worksheet

Hello all -

I am running into similar problems to Pat from the following post:

http://groups.google.com/group/micro...tection&rnum=1

The code I have works when the sheet is unprotected, but does not when
the sheet is protected. I have even tried adding code to protect and
unprotect while running the macro, but it doesn't help. Same
problem. The "Sub Worksheet_Change" does get called but it always
returns "True" from HasValidation, instead of "False" like it does
when the worksheet is unproteced and I try to paste a blank cell over
a cell with data validation.

PLEASE HELP.

I have the following code:

Private Sub Worksheet_Change(ByVal Target As Range)

'Does the validation range still have validation?
Dim vRangeName As Variant
Dim bRangeCheck As Boolean
Dim i As Integer

i = 1

For i = 1 To 10

vRangeName = "ValidationRange" & i
bRangeCheck = RangeExists(vRangeName)

If bRangeCheck = True Then
'Unprotect sheet
ActiveSheet.Unprotect "password"

'Does the validation range still have validation?
If HasValidation(Range(vRangeName)) Then
'No Action
Else
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
MsgBox "Your last operation was canceled, " & _
"as it would have deleted data validation rules.",
vbCritical, "DDS Invoice Message"
End If

'reprotect sheet
ActiveSheet.Protect "password"
End If
Next

End Sub

Public Function RangeExists(rangeName As Variant) As Boolean
Dim vRange As Variant
RangeExists = False

On Error GoTo BadRange
If rangeName < "" Then
vRange = Range(rangeName)
RangeExists = True 'will raise error where range does not
exist
'therefore to get here, it must
Exit Function
End If

BadRange:
End Function

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 If
End Function

Thanks-
KES

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hyperlinks in cells in a protected worksheet not working NealB Excel Discussion (Misc queries) 3 September 11th 08 10:20 PM
Validation error when worksheet is protected Tom Emmery[_2_] Excel Programming 2 September 7th 07 09:54 PM
Strange problems with setting hidden property of a range when sheet protected with UserInterfaceOnly [email protected] Excel Programming 2 June 6th 06 04:15 PM
Protected Worksheet - tabs stop working in certain areas bucketowater Excel Discussion (Misc queries) 0 January 26th 06 05:27 AM
Validation.Modify Runtime Error in Protected Worksheet Kent Klingler Excel Programming 3 May 13th 04 09:18 PM


All times are GMT +1. The time now is 01:44 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"