Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 73
Default Protecting a Sheet - Issue

I have the following code that I run to protect a sheet

ActiveSheet.Protect Password:="xyz", DrawingObjects:=True,
Contents:=True, Scenarios:=True
Sheets("Visit Log").Select
ActiveSheet.Protect Password:="xyz", DrawingObjects:=True,
Contents:=True, Scenarios:=True
Range("D7").Select

I have all required cells within the sheet "Visit Log" unlocked. These
unlocked cells are Data Validation drop down lists which run a change
event code when selected (just changes the background colour)

My problem is that when my sheet is protected with the above code, the
Change event code doesn't work

Any ideas?

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,203
Default Protecting a Sheet - Issue

I just double-checked (Excel 2003) and had no trouble detecting a
Worksheet_Change event based on selecting from an Unlocked cell with a list
via data validation in it. So have to look elsewhere.

I recently ran into similar situation and for a while I thought the _Change
wasn't firing in a group of merged cells set up with data validation/list.
What actually turned up in that situation was that there was another user
defined function that used Application.Volatile in it that was interrupting
the processing in the _Change code and never returning control to the
_Change() code once it had done so.

I think you're going to have to single step through the code to see all that
is going on and determine if something like that is happening. Just put a
breakpoint early on in your _Change() event code (or just a Stop instruction)
and then when you get there, start using [F8] to single step through it all,
following closely to see where it goes astray or fails completely.

" wrote:

I have the following code that I run to protect a sheet

ActiveSheet.Protect Password:="xyz", DrawingObjects:=True,
Contents:=True, Scenarios:=True
Sheets("Visit Log").Select
ActiveSheet.Protect Password:="xyz", DrawingObjects:=True,
Contents:=True, Scenarios:=True
Range("D7").Select

I have all required cells within the sheet "Visit Log" unlocked. These
unlocked cells are Data Validation drop down lists which run a change
event code when selected (just changes the background colour)

My problem is that when my sheet is protected with the above code, the
Change event code doesn't work

Any ideas?

Thanks


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,203
Default Protecting a Sheet - Issue

Another thought: since you are using the change event to make a change, you
may be getting in an infinite loop within the _Change() event itself. Be
sure you turn off EnableEvents before executing any code in there to change
anything.

Consider this:
Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox "Change Event Fired"
Range("G8") = "changed from code"
End Sub

In this case, G8 is actually a locked cell, but no matter. If you run it
like this, you'll get the "Change Event Fired" message over and over until
you use [Ctrl]+[Break] to stop it.

Change it a little like this:
Private Sub Worksheet_Change(ByVal Target As Range)
MsgBox "Change Event Fired"
Application.EnableEvents = False
Range("G8") = "changed from code"
Application.EnableEvents = True
End Sub

And it will work and make the change, but since G8 is locked and the sheet
is protected, the error message comes up telling me that I'm trying to alter
contents of a locked cell on a protected sheet - as expected.

" wrote:

I have the following code that I run to protect a sheet

ActiveSheet.Protect Password:="xyz", DrawingObjects:=True,
Contents:=True, Scenarios:=True
Sheets("Visit Log").Select
ActiveSheet.Protect Password:="xyz", DrawingObjects:=True,
Contents:=True, Scenarios:=True
Range("D7").Select

I have all required cells within the sheet "Visit Log" unlocked. These
unlocked cells are Data Validation drop down lists which run a change
event code when selected (just changes the background colour)

My problem is that when my sheet is protected with the above code, the
Change event code doesn't work

Any ideas?

Thanks


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
macro unouwanme Excel Discussion (Misc queries) 9 August 31st 06 09:38 PM
Protecting Sheet purplerayn Excel Worksheet Functions 1 October 21st 05 12:55 AM
Sheet Protecting password Nick Excel Discussion (Misc queries) 1 June 30th 05 12:43 AM
Protecting a sheet that includes a solver function 20002238Rijk Excel Worksheet Functions 3 December 9th 04 09:53 AM
Naming & renaming a sheet tab Cgbilliar Excel Worksheet Functions 1 November 7th 04 05:57 PM


All times are GMT +1. The time now is 01:46 PM.

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"