Forum Discussion
Excel worksheet protect from editing in excel
- Feb 03, 2021
It's possible if you're willing to use VBA.
Step 1:
- Select all the cells that the user should be able to fill.
- Press Ctrl+1 to activate the Format Cells dialog.
- Activate the Protection tab.
- Clear the Locked check box.
- Click OK.
Step 2:
- Activate the Review tab of the ribbon.
- Click 'Protect Sheet'.
- Specify what the user should be able to do.
- At the very least, leave the check box 'Select unlocked cells' ticked.
- If desired, specify a password that will be needed to unlock the sheet. If you do, make sure you remember it!
- Click OK.
- If you specified a password, you'll have to enter it again as confirmation.
Step 3:
- Right-click the sheet tab.
- Select 'View Code' from the context menu.
- Copy the following code into the worksheet module:
Private Sub Worksheet_Change(ByVal Target As Range) Dim rng As Range Me.Unprotect Password:="secret" For Each rng In Target If rng.Value <> "" Then rng.Locked = True End If Next rng Me.Protect Password:="secret" End Sub
- Replace "secret" with the password you used; if you didn't specify a password, use "".
- Switch back to Excel.
- Save the workbook as a macro-enabled workbook (.xlsm).
- Make sure that the user allows macros when they open the workbook.
It's possible if you're willing to use VBA.
Step 1:
- Select all the cells that the user should be able to fill.
- Press Ctrl+1 to activate the Format Cells dialog.
- Activate the Protection tab.
- Clear the Locked check box.
- Click OK.
Step 2:
- Activate the Review tab of the ribbon.
- Click 'Protect Sheet'.
- Specify what the user should be able to do.
- At the very least, leave the check box 'Select unlocked cells' ticked.
- If desired, specify a password that will be needed to unlock the sheet. If you do, make sure you remember it!
- Click OK.
- If you specified a password, you'll have to enter it again as confirmation.
Step 3:
- Right-click the sheet tab.
- Select 'View Code' from the context menu.
- Copy the following code into the worksheet module:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Me.Unprotect Password:="secret"
For Each rng In Target
If rng.Value <> "" Then
rng.Locked = True
End If
Next rng
Me.Protect Password:="secret"
End Sub
- Replace "secret" with the password you used; if you didn't specify a password, use "".
- Switch back to Excel.
- Save the workbook as a macro-enabled workbook (.xlsm).
- Make sure that the user allows macros when they open the workbook.
HansVogelaar Thank you for your answer. I tried the macro but it does not even allow them to enter any data after the code. I actually want all users to be able to add information but not to edit it after they entered the data. This is for commission purposes.
- HansVogelaarFeb 03, 2021MVP
Did you follow step 1 - unlocking cells? If you don't do that, all cells will be locked!
- JanedbFeb 04, 2021Iron Contributor
HansVogelaar Hi, yes I unlocked the cells but it locks all capturing of data as well. I want the user to add information but not edit the information.
- HansVogelaarFeb 04, 2021MVP
Do you mean that the user should be able to add information in a cell that already has been filled before, but not edit the existing content?