+ Reply to Thread
Results 1 to 4 of 4

Cursor on locked cell causes sheet protection code error.

  1. #1
    Valued Forum Contributor
    Join Date
    02-26-2010
    Location
    Chattanooga, TN
    MS-Off Ver
    Excel 2003/2007/2010/2016
    Posts
    432

    Talking Cursor on locked cell causes sheet protection code error.

    Hello!

    1. On a new workbook, uncheck protection for one cell (ex, A1).
    2. For sheet protection, uncheck all but "Select unlocked cells".
    3. Run the following code to protect all sheets in the workbook.
    4. If the cursor is in A1 when you run the code, it all works smoothly.
    5. If the cursor is in other than A1, the sheet still protects, but you get a error message (1004: Method 'Goto of object'_Aplication' failed).

    The problem is that code is trying to protect the whole sheet including the locked cell that the cursor is sitting on.

    I was thinking that maybe the code could jump to an unlocked cell before running, but then I have some "info-only" sheets where all the cells are locked (so there is nowhere to jump to.)

    Anyone know how to fix this?

    Respectfully,
    Lost

    Please Login or Register  to view this content.
    Last edited by leaning; 06-07-2011 at 11:12 AM. Reason: Solved!

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Cursor on locked cell causes sheet protection code error.

    Hi,

    Why not use the following two lines either side of the GOTO instruction

    Please Login or Register  to view this content.
    Regards
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Cursor on locked cell causes sheet protection code error.

    Hi,

    There's no need to select each worksheet as you loop through them so you then shouldn't need to go back to the original one as you won't move away from it:

    Please Login or Register  to view this content.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  4. #4
    Valued Forum Contributor
    Join Date
    02-26-2010
    Location
    Chattanooga, TN
    MS-Off Ver
    Excel 2003/2007/2010/2016
    Posts
    432

    Re: Cursor on locked cell causes sheet protection code error.

    Domski,

    Perfect! Thanks! Repped!

    Respectfully,

    Lost

+ 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