Consulting

Results 1 to 9 of 9

Thread: locking cells without sheet protection

  1. #1

    Exclamation locking cells without sheet protection

    Hi,

    I am using the following code to lock certain cells in the worksheet.

    ActiveSheet.Cells.Locked = False
    ActiveSheet.Range("B3:D3").Locked = True
    ActiveSheet.Protect
    ActiveSheet.EnableSelection = x1UnlockedCells
    But this is protecting the worksheet and not allowing further operations.
    Is there a way to lock cells from editing without using sheet protection?

    Thanks for your help.
    Last edited by Aussiebear; 04-23-2023 at 08:31 PM. Reason: Added code tags

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,796
    Location
    Not really, although you could use a worksheet_change event to undo the changes if any cells in a specific range are altered.
    Be as you wish to seem

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,446
    Location
    Protection can be geared to specific operations, so you should be able to allow 'further operations'.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Regular
    Joined
    Aug 2011
    Posts
    11
    Location
    You can use Data Validation on the cells you want "locked". Type the information you want into the cell, select the cell, then go to Data --> Validation --> Allow (Custom) --> Make the formula equal to the cell you just typed your information into (eg. =A12). This isn't fool proof, but it might be enough to simply deter editing.

  5. #5
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,776
    Another alternative using Data Validation is to enter the data or formula in the cell and then put Validation on the cell with the custom formula =FALSE and uncheck the ignore blanks box.

  6. #6

    Thanks

    Thanks a lot for your help

  7. #7
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,796
    Location
    Mike,
    That would not prevent deleting the contents or pasting over it, would it?
    Be as you wish to seem

  8. #8
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,776
    The method I suggested will not protect against Paste or VBA entry into the cell.

    It will protect against Backspace+Enter, it will not protect against Clear or ClearContents.

    On the plus side, the protected cell can be Cut and pasted whereever one wants it.

  9. #9
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,796
    Location
    It also will not protect against the delete key which is generally more prevalent than Backspace and Enter, I suspect (except perhaps in the Mac arena). In any event at least the asker has many options.
    Be as you wish to seem

Posting Permissions

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