Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Protect/Unprotect Not Working

I have a sheet with lots of Option Buttons and a few input cells.

The sheet is protected and each macro starts ActiveSheet.Unprotect and
finishes ActiveSheet.Protect

This is the start of the macro for Option Button 10

ActiveSheet.Unprotect
OptionButton4.Value = True (To reset to the default button in another
group)
Application.ScreenUpdating = False
Range("J4").Select
ActiveCell.FormulaR1C1 = "2"

For some reason it keeps falling over at the last line above with a run-time
error 1004 message saying the cell or chart I'm trying to change is protected
and therefore read only.

This doesn't seem to happen every time the macro runs but quite frequently.

I don't understand how this can happen given the first line in the macro
unprotects the sheet.

I'm confused. Is there a better way to write this that would be more robust?

Thanks a lot
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 77
Default Protect/Unprotect Not Working

Hi

If the code is being run from a CommandButton make sure that the
TakeFocusOnClick property of the CommandButton is set to False. Also,
although I have seen it said that it is not necessary, activate the sheet
you want and select a cell on that sheet before the unprotect statement and
your problem should disappear.

Worksheets("Sheet1").activate
Range("a1").select
ActiveSheet.Unprotect

HTH

Ken


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
Protect, unprotect Pyrite Excel Discussion (Misc queries) 0 August 15th 08 03:18 PM
protect and unprotect Andrew[_51_] Excel Programming 1 October 13th 05 07:24 PM
protect and unprotect Andrew[_51_] Excel Programming 2 October 13th 05 06:44 PM
Protect/Unprotect w/ VBA not working as supposed... HBj Excel Programming 3 October 7th 05 05:16 PM
Unprotect and protect.... Wilfrid Excel Programming 1 July 28th 04 03:13 AM


All times are GMT +1. The time now is 02:24 AM.

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

About Us

"It's about Microsoft Excel"