

This says that a cell should be locked only if cell A1 was edited and it is not empty. Looking at the macro above, this is the line that limits the macro to run only on specific cells: If Target.Address = "$A$1" And Target.Value "" Then I will show you how to edit this macro in the examples below. It checks which cell was edited and, if a certain cell was edited, it is then locked. This example is a generic example that is easy to modify. To do this, right-click the tab of the desired worksheet and click View Code and paste the macro into the window that opens. This macro needs to be installed into the worksheet where it will run. It unprotects the worksheet, locks the cell, and then re-protects the sheet.

The important code is this part: ActiveSheet.Protect Contents:=False If Target.Address = "$A$1" And Target.Value "" Then

Macro to Auto-Lock Cells Private Sub Worksheet_Change(ByVal Target As Range) This needs to be done so that only specific cells that we choose will be locked from editing. Now, none of the cells in the worksheet are protected, which means that all of the cells in the worksheet will be editable when you go to protect the worksheet. Go to the Protection tab and uncheck the Locked option at the top.Right click in the worksheet and choose Format Cells.Select all of the cells by hitting Ctrl + A or clicking the square next to row 1 and column A.The first thing you have to do is to unlock all of the cells in the worksheet. Lock Cell Other Than the One that was Edited This is different than just locking an entire spreadsheet because you still want to be able to edit and work with the other cells in the worksheet without having to select and unlock them individually. This macro allows you to have a cell automatically locked after a user enters something into it or into another specific cell, range, column, or row.
