How to automate the process of locking cells when they contain data

Anonymous
2016-02-24T05:54:42+00:00

In Excel 2003, to protect data entered in cells, and allow only editing empty cells, I do the following:

In an empty worksheet, I select all cells, and Format | cells | protection | uncheck locked property.

After I enter data in some cells, I select these cells and check the locked property.

To protect the entered data from being edited, I protect the sheet by

Tools | Protection | Protect Sheet | Allow users to Select locked cells and Select unlocked cells

Now only the empty cells could be edited.

My question is that:

Is it possible to automate the process of letting the cells to be unlocked when they are empty, and to be locked when they contain data? So that I do not have to select the cells containing data and lock them manually each time I enter data in them.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

10 answers

Sort by: Newest
  1. Anonymous
    2016-02-28T03:27:12+00:00

    Hello HansV

    Your code now is perfect. Thank you very very much.

    Was this answer helpful?

    0 comments No comments
  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Anonymous
    2016-02-27T04:08:13+00:00

    Hello  HansV

    Here is the link to the files, one applying only your second formula, the other applying the 2 formulae.

    https://onedrive.live.com/redir?resid=220F1BA8E872A001!122&authkey=!ACGO-lq6KKXCdGU&ithint=folder%2c

    Was this answer helpful?

    0 comments No comments
  4. HansV 460.5K Reputation points MVP Volunteer Moderator
    2016-02-26T10:55:50+00:00

    The screenshots that you uploaded don't display correctly for me. That's probably not your fault - the forum software is very buggy - but it means I have no idea what goes wrong.

    Could you create a stripped-down copy of the workbook (without sensitive information) and make it available through one of the websites that let you upload and share a file, such as FileDropper (http://filedropper.com) or DropBox (https://www.dropbox.com). Then post a link to the uploaded and shared file here.

    Or register at www.eileenslounge.com (it's free) and start a thread in the Excel forum. You can attach files up to 250 KB to a post there (zipped if necessary).

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2016-02-26T05:15:47+00:00

    Thank you  HansV very much for your time.

    I followed your instructions very carefully.

    This is what happened

    1- Using a copy of my original file, when I entered your first code in the worksheet module, and your second code in the standard module then pressed F5; the cells already contained data could no longer be edited, that is good. But when I tried to enter data in empty cells this was possible but I got the error message attached 

     When I tried to unprotect the sheet, this was not possible and gave me the error message attached (I am sure my password is correct which is secret as in your code).

    I saved the file, exit and reopened it.

    Now the cells edited after applying your codes could still be modified (with the same error message display) and could not be protected.

    How can these errors be fixed?

    2- Using another copy of my original file, when I did not enter your first code in the worksheet module, and I only used your second code in the standard module and pressed F5; the cells already contained data could no longer be edited, and I can edit empty cells with no error message. That is exactly what I need.

    I saved the file, exit and reopened it, now the data entered after applying your code could still be edited and are not protected.

    When I tried to unprotect the sheet, this was not possible and gave me the same error message as in method 1 (I am sure my password is correct which is secret as in your code).

    Was this answer helpful?

    0 comments No comments