+ Reply to Thread
Results 1 to 2 of 2

Protect/Unprotect Not Working

  1. #1
    nospaminlich
    Guest

    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. #2
    Ken Macksey
    Guest

    Re: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1