+ Reply to Thread
Results 1 to 8 of 8

How to lock/protect a cell that is selected in a macro range

  1. #1
    Registered User
    Join Date
    01-07-2014
    Location
    United States
    MS-Off Ver
    Excel 2003, 2010
    Posts
    15

    How to lock/protect a cell that is selected in a macro range

    Hi,

    I have a sheet where I want to protect a cell so it can't be modified, so I locked the cells in question, but then I have a macro that selects a range with the locked cells within it and I get a runtime error on the macro. I'm assuming because it can't select the range with the locked cells in it. On my protection specifications I added the permission to select locked cells, but it still gave me the runtime error.

    Is there a way around this? I'd like to run my code and also keep a few cells protected that I need to.

    Thanks!

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: How to lock/protect a cell that is selected in a macro range

    unprotect the sheet in code. do whatever you want. reprotect the sheet in code

    Something like this:

    Please Login or Register  to view this content.
    Last edited by stnkynts; 01-08-2014 at 11:44 PM.

  3. #3
    Registered User
    Join Date
    01-07-2014
    Location
    United States
    MS-Off Ver
    Excel 2003, 2010
    Posts
    15

    Re: How to lock/protect a cell that is selected in a macro range

    OK. On the code snippet if I already have a sub I can just drop in the "Sheets" lines? Thanks!

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: How to lock/protect a cell that is selected in a macro range

    Yup. Just put one line at the top and the other at the bottom. With your code inbetween.

  5. #5
    Registered User
    Join Date
    01-07-2014
    Location
    United States
    MS-Off Ver
    Excel 2003, 2010
    Posts
    15

    Re: How to lock/protect a cell that is selected in a macro range

    Ok.Thanks!

  6. #6
    Registered User
    Join Date
    06-13-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: How to lock/protect a cell that is selected in a macro range

    Hi Stnkynts,
    Can you tell me if this approach (adding the sheets.Unprotect and sheets.Protect code) would work if the macro was within the Personal XLSB workbook. Would you need to specify to use the active workbook for example?

    Please Login or Register  to view this content.
    My apologies in advance if this should be in a new post, but it seemed very closely related...

  7. #7
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: How to lock/protect a cell that is selected in a macro range

    @fur. It should be a new post. But to answer your question, are you sure that one of your sheets (tab) is named "Sheet1". That is probably what is giving you this error.

  8. #8
    Registered User
    Join Date
    06-13-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: How to lock/protect a cell that is selected in a macro range

    Thanks for your reply, yes my macro was calling for "Sheet1" while the actual sheet name had been changed to "Data". Error message resolved once the names were matched up.
    Many thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Lock & protect range given non blank value
    By chris100 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-09-2012, 02:52 PM
  2. Lock/Protect another cell / a range of cells for specific value of one cell
    By ohlalayeah in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 07-04-2012, 04:25 AM
  3. Replies: 0
    Last Post: 07-03-2012, 05:42 AM
  4. Replies: 0
    Last Post: 01-06-2011, 05:58 PM
  5. Protect/Lock Cell Range.
    By D_Rennie in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-15-2009, 04:33 AM

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