I looked high and low for a way to lock isolated cells in Excel without a need to unprotect the whole worksheet whenever any cell was being edited, and I finally came across two options; the first was my preference:
Option 1:
To ONLY protect or lock individual cells in Excel without locking the whole worksheet
- Select the whole worksheet using either ‘Ctrl + A’ or click in the top left corner of the sheet (little pale arrow).
- Right click any cell and select “Format Cells …”. In the Protection tab, remove the checkmark next to “Locked”. Click OK.
- Now select the cells or the range that you want to protect. Right-click on it and select “Format cells …”.
- In the Protection tab, check the box next to ‘Locked’.
- Once the cells you want to lock are ticked, go to the tab and select ‘Review’, then ‘Protect Sheet’.
- Ensure you tick ‘Select locked cells’ and ‘Select unlocked cells’ in the ‘All users of this worksheet…’ submenu.
- Assign a password and confirm twice.
Note that the password will only be needed if unlocking the worksheet to edit the locked cells. If other unlocked cells are being manipulated, there will be no need to unlock/unprotect the worksheet.
To summarise, unlock the whole sheet first, then lock the cells you want protected, then protect the sheet.
Option 2:
You can use VBA code to prevent some cells from being edited, but that only helps with accidental edits. Someone who knows a bit about Excel can easily circumvent it by either opening the workbook without allowing macros, or by temporarily disabling events.
- Right-click the sheet tab.
- Select ‘View Code’ from the context menu.
- Copy the code listed below atm no 8 into the worksheet module.
- Change A2,C2,A4,C4 to the list of cells that you want to protect. You can use ranges too: A2:B10,D2:H10
- Switch back to Excel.
- Save the workbook as a macro-enabled workbook (*.xlsm).
- Instruct users to allow macros when they open the workbook.
- Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Range(“A2,C2,A4,C4”), Target) Is Nothing Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
End Sub
Discussion
No comments yet.