Sub topic 10
Protecting sheets and allowing edits to specific ranges
This chapter assumes you can already save a workbook to OneDrive or SharePoint, share it with the Share button, and set view or edit permissions on a link. You should also know the basics of AutoSave and co-authoring from the earlier chapters. Here you will learn how to lock parts of a shared workbook so that collaborators can edit only the cells they should.
What sheet protection does and does not do
Sheet protection stops edits to cells marked as locked. It works inside the workbook, so it applies to every person who opens the file with edit access.
It is not a security feature. Anyone with edit permission on the file can remove protection if you set no password. If you set a password, it only stops casual changes, because the file can be copied and the password can be attacked offline. The real access control is the sharing permission from the earlier chapters.
| Control | Where it is set | What it stops |
|---|---|---|
| Link or invite permission (view or edit) | Share dialog | Who can change the file at all |
| Sheet protection | Review > Protect Sheet | Edits to locked cells by anyone with edit access |
| Allowed edit ranges | Review > Allow Edit Ranges | Lets chosen areas stay editable on a protected sheet |
| Workbook structure protection | Review > Protect Workbook | Adding, deleting, renaming, or moving sheets |
Use sharing permissions to decide who can open the file. Use protection to prevent accidents by people who are allowed in.
The locked-by-default model
Every cell has a Locked property, and it is on by default. The property has no effect until the sheet is protected. This leads to a simple working model:
- Decide which cells collaborators should edit, such as input cells.
- Unlock only those cells.
- Protect the sheet.
After step 3, locked cells reject edits, and unlocked cells accept them from anyone with edit access.
Unlocking input cells
- Select the cells that collaborators may change. Hold Ctrl to add separate areas.
- Press Ctrl+1 to open Format Cells and go to the Protection tab.
- Clear the Locked check box and select OK.
Do this before you protect the sheet. If you protect first, you must unprotect to change which cells are unlocked.
A quick way to review the layout is to apply a distinct fill color to every input cell. Color does not affect protection, but it shows collaborators where they may type.
Protecting the sheet
- Select Review > Protect Sheet.
- Enter a password if you want one. You can leave it blank.
- Choose what users may still do on locked cells. The list includes selecting locked cells, formatting columns, inserting rows, sorting, and using AutoFilter.
- Select OK.
The options matter more in shared workbooks than in single-user files. Two examples:
- If collaborators need to filter a table, tick Use AutoFilter. Sorting and filtering a range also require the cells in that range to be unlocked.
- If you clear Select locked cells, people cannot click formula cells. This hides nothing, because the formulas are still stored in the file, but it reduces accidental edits.
In a co-authoring session, protection takes effect for everyone after the change is saved and synced. A collaborator who is mid-edit in a cell that you just locked may see their entry rejected. Protect sheets before inviting people to a busy session, or tell them first.
Allowing edits to specific ranges
Review > Allow Edit Ranges (shown on a sheet that is not yet protected) lets you name ranges that stay editable when the sheet is protected. You choose the following:
- A title for the range, such as
Inputs. - The cells it covers.
- An optional range password.
For many shared workbooks you do not need this feature. Unlocking cells (see above) gives the same result with fewer moving parts. Allow Edit Ranges is useful when different groups need different passwords, for example when finance edits one block and operations edits another.
Range passwords have a cost in co-authoring. Each person must type the password to edit the range, and passwords are not tied to a person, so you cannot tell who knew them. Excel for the web may not prompt for range passwords in the same way as the desktop app. Test the exact scenario in the apps your collaborators use, and check Microsoft's current documentation, because support has changed between versions.
Protecting the workbook structure
Sheet protection does not stop someone from deleting a whole sheet. To prevent that, choose Review > Protect Workbook and tick Structure. Collaborators can still edit cells on unprotected sheets, but they cannot add, delete, hide, rename, or move sheets.
Protecting structure is valuable when other workbooks or formulas refer to sheet names. A deleted sheet turns references into #REF! errors, and Version History is then the only way back.
Setting up protection with VBA
You can apply the same setup to many sheets with a macro. This macro unlocks a range of input cells, locks everything else, and protects the active sheet without a password.
Sub ProtectForCollaboration()
Dim ws As Worksheet
Set ws = ActiveSheet
ws.Unprotect ' fails if a password is set
ws.Cells.Locked = True ' lock everything first
ws.Range("B5:E20").Locked = False ' then unlock the input block
ws.Protect DrawingObjects:=True, _
Contents:=True, _
Scenarios:=True, _
AllowFormattingColumns:=True, _
AllowFiltering:=True
End SubThe macro has these limits:
ws.Unprotectraises a run-time error if the sheet already has a password. Pass the password as an argument in that case.- Macros run in the desktop app only. Excel for the web does not run VBA, so the result must be applied before others open the file.
- Putting a password in code stores it in readable form in the file, so use this for convenience, not secrecy.
To define a named editable range from code, use ws.Protection.AllowEditRanges.Add Title:="Inputs", Range:=ws.Range("B5:E20") before you call ws.Protect. The password argument is optional.
Common errors and how to read them
- "The cell or chart you're trying to change is on a protected sheet." The cell is locked. Ask the owner to unlock it, or if you are the owner, unprotect the sheet and clear Locked on those cells.
- Protection seems to do nothing. The sheet is not protected yet, or the cells were unlocked. Check Review: if the button says Unprotect Sheet, protection is on.
- Collaborators can edit everything. The sheet is protected on your copy but another sheet in the workbook is not. Protection is per sheet, so check each tab.
- Forgotten password. Excel cannot recover it. Keep the password in your team's password manager, and keep an earlier version in Version History as a fallback.
- Table rows cannot be added. Tables cannot expand on a protected sheet. Either leave the table sheet unprotected, or give users a pre-sized table with spare rows.
- Sorting is greyed out. The range contains locked cells. Unlock the whole sorted block and tick Sort in the Protect Sheet options.
A practical layout
A layout that works well for shared workbooks follows this pattern:
- An Inputs sheet with unlocked, color-filled cells, protected without a password.
- A Calculations sheet where every cell is locked.
- A Report sheet where every cell is locked and formatting is allowed.
- Workbook structure protected, so sheets cannot be deleted.
Collaborators type only on Inputs and never touch the formulas. If someone damages a cell by mistake, use Version History to restore it. The next chapter group builds on this idea when it looks at laying out a workbook to avoid edit collisions.
Exercise
A shared sheet is protected without a password. A teammate with edit access says they can still type into cell B6, but not into cell D6. What is the most likely reason, and how would you make D6 editable?
Show answer
B6 is unlocked and D6 is locked. Locking only takes effect once the sheet is protected, so the protected sheet now rejects edits to D6. To make D6 editable, choose Review > Unprotect Sheet, select D6, open Format Cells (Ctrl+1) > Protection and clear Locked, then protect the sheet again.
Exercise
You want collaborators to sort and filter a table of inputs on a protected sheet. Name two settings you must check.
Show answer
In the Protect Sheet options, tick Sort and Use AutoFilter. Also make sure every cell in the range being sorted or filtered is unlocked, because sorting a range that contains locked cells is blocked on a protected sheet.
Exercise
Why is sheet protection not a substitute for setting a link to "view only" for people who should not change the file?
Show answer
Anyone with edit access can remove unprotected-sheet protection, and a password only slows down someone determined. Protection stops accidental changes inside the file, but the sharing permission decides who can change the file at all.