+ Reply to Thread
Results 1 to 8 of 8

Unable to lock cells

  1. #1
    Forum Contributor
    Join Date
    07-04-2018
    Location
    Dallas
    MS-Off Ver
    MS 365 Version 2302
    Posts
    209

    Unable to lock cells

    Hi,

    I am trying to lock cells in excel when I run macro, but id doesn't work.

    Below is the code.

    Public Sub submit_button()
    Range("B4:B8").Locked = True
    End Sub

    B4:B8 are the cells which i am trying to lock. Please let me if I am missing anything here.

    Thanks in advance

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Unable to lock cells

    Sheet must be unprotected
    Please Login or Register  to view this content.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Forum Contributor
    Join Date
    07-04-2018
    Location
    Dallas
    MS-Off Ver
    MS 365 Version 2302
    Posts
    209

    Re: Unable to lock cells

    Thanks Kev. That works.

    I need cells to be locked based on value of another cell which is a named range 'choice'.

    If choice = NWC. cells should be locked else locked = False.

    Can we have condition on password protected code

  4. #4
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Unable to lock cells

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    07-04-2018
    Location
    Dallas
    MS-Off Ver
    MS 365 Version 2302
    Posts
    209

    Re: Unable to lock cells

    Hi Kev,

    Thanks for the reply.

    I am trying to understand the logic of

    .Range("B4:B8").Locked = ([choice] = "NWC")

    I am looking for Locked to be true is if Choice is "NWC". If Choice is other than NWC, Locked should be 'False'.

    The logic seems to be assigning Locked value = ([choice] = "NWC")

    Please let me know if I am understanding it right

  6. #6
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Unable to lock cells

    The code is written to achieve what you require
    The locked status of B4:B8 is set to the result of what is inside the parenthesis
    - inside the parenthesis equates to true or false

  7. #7
    Registered User
    Join Date
    12-03-2008
    Location
    US
    Posts
    8

    Re: Unable to lock cells

    I have a similar question, but I want to lock certain cells (formulas, column titles, etc) from being edited, but need the input cells to be editable. Also, I need to easily be able to delete all the cells that have input data without deleting the formulas or content in the protected cells.
    So, using a protected sheet doesn't quite work. It seems to be a quicker way of selecting cells and locking them under protections and then protecting the worksheet.

    Any options to accomplish what I'm trying for?
    Thanks!

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: Unable to lock cells

    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ 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. [SOLVED] how to lock selected cells lock in excel
    By koteswar in forum Excel General
    Replies: 10
    Last Post: 10-25-2018, 02:38 AM
  2. Unable to lock a table column reference in a formula
    By DGAlamo in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 07-05-2016, 12:12 PM
  3. Excel 2011 - Unable to Unlock Scroll Lock on MacBook Pro
    By A A Frank in forum Excel General
    Replies: 4
    Last Post: 09-29-2013, 06:21 PM
  4. Unable to use cell lock feature - XL2010
    By Beth Hoffmann in forum Excel General
    Replies: 2
    Last Post: 06-28-2013, 03:04 PM
  5. Replies: 2
    Last Post: 02-22-2012, 10:10 AM
  6. Excel 2007 : Unable to Lock Textbox in 2007
    By scottmalone in forum Excel General
    Replies: 3
    Last Post: 02-13-2009, 05:57 AM
  7. Can I lock cells or do I have to lock the worksheet?
    By jmbtexas in forum Excel General
    Replies: 4
    Last Post: 11-11-2008, 02:26 PM

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