Sub topic 6
Protecting sheets and ranges
This chapter assumes you already know the three roles (Viewer, Commenter, Editor), can share a spreadsheet with named people, and are comfortable selecting cell ranges and switching between sheet tabs. Roles control what someone can do in the whole spreadsheet. Protection narrows that for part of it. This chapter covers how protection works, how to set it up, and where it fails.
What protection does and does not do
Protection restricts who can edit a specific sheet (tab) or range of cells. It sits on top of the sharing roles and can only take edit rights away. It cannot give anyone more access than their role allows.
- A Viewer or Commenter cannot edit anything, protected or not.
- An Editor can edit everything in the spreadsheet unless a protection excludes them.
- The owner of the spreadsheet and the person who created a protection can always change that protection.
Protection is a guard against accidents and casual changes. It is not a way to hide data. Anyone who can view the spreadsheet can still read protected cells. They can also copy the whole spreadsheet, and the copy has no restrictions that apply to them, because they own it. If the data must stay secret, do not share the spreadsheet with that person at all.
Protecting a sheet in the interface
To protect a whole tab:
- Right-click the sheet tab at the bottom and choose Protect sheet. You can also use Data > Protect sheets and ranges.
- In the Protected sheets & ranges panel, click Add a sheet or range if the panel is empty, then make sure the Sheet tab is selected.
- Pick the sheet from the drop-down list.
- Optionally click Except certain cells to leave some cells open for everyone who can edit.
- Click Set permissions.
In the permissions dialog you choose between two modes:
| Mode | Effect |
|---|---|
| Show a warning when editing this range | Anyone with Editor access can edit, but they see a confirmation prompt first. Nothing is blocked. |
| Restrict who can edit this range | Only the people you list can edit. Everyone else can only view. |
The warning mode is useful for cells that people should rarely change, such as a tax rate. It reminds them but does not enforce anything.
When you choose Restrict who can edit this range, you pick from a drop-down: Only you, Only domain (in a Google Workspace organization, people in your domain), or Custom. With Custom, you tick individual people from the list of current editors. You can also copy the permissions from another range.
Only people who already have Editor access appear in the list. If someone is missing, they are a Viewer or Commenter, and they cannot edit anyway.
Protecting a range
The steps are the same, but you select the Range tab and enter a range in A1 notation, such as B2:B20 or Budget!D2:F40. You can also select the cells first and then choose Data > Protect sheets and ranges, which fills in the range for you.
Give each protection a short description, such as "Totals - owner only". Descriptions appear in the panel list and make it much easier to audit later.
Protecting a sheet except for input cells
A common pattern is a form-like sheet where people fill in a few cells and everything else stays fixed.
- Protect the whole sheet.
- Under Except certain cells, add the input ranges, for example
C5:C12. - Set permissions to Only you or a custom list.
Everything outside the exceptions is locked for the other editors. The excepted cells remain editable by anyone with Editor access to the spreadsheet.
How protections combine
A cell can be covered by more than one protection, for example a protected sheet plus a protected range inside it. An editor must be allowed by every protection that covers the cell. If any one of them excludes the person, the edit is blocked.
The list of protections is shown in the Protected sheets & ranges panel. Click an entry to edit its range, description, or permissions, or click the trash icon to delete it.
What protection affects besides typing
Protection also limits other actions on the protected area for people who are not allowed to edit it. They cannot:
- Delete or rename a protected sheet.
- Delete rows or columns that contain protected cells.
- Sort a range that includes protected cells.
- Paste over protected cells.
Some actions work around cells rather than through them. For example, an editor who is blocked can still copy values out of a protected range and paste them elsewhere, because copying is a read operation.
Automating protection with Apps Script
If you write many protections, or must apply the same one to many spreadsheets, use Apps Script. The following function protects the active sheet so only the user running the script can edit it.
function protectActiveSheet() {
const sheet = SpreadsheetApp.getActiveSheet();
const protection = sheet.protect().setDescription('Totals - owner only');
const me = Session.getEffectiveUser();
protection.addEditor(me);
protection.removeEditors(protection.getEditors());
if (protection.canDomainEdit()) {
protection.setDomainEdit(false);
}
}The order matters. The script first adds the current user, then removes every other editor. If you removed all editors first, you could remove yourself. canDomainEdit() checks whether the spreadsheet belongs to a Workspace domain, and setDomainEdit(false) stops everyone in that domain from editing through the domain rule.
To protect a range instead of a sheet, call protect() on a Range:
function protectTotals() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Budget');
const range = sheet.getRange('D2:D20');
const protection = range.protect().setDescription('Totals');
protection.addEditor(Session.getEffectiveUser());
protection.removeEditors(protection.getEditors());
}To list existing protections, use sheet.getProtections(SpreadsheetApp.ProtectionType.RANGE) or SpreadsheetApp.ProtectionType.SHEET. Each returned object has getRange(), getDescription(), and remove().
Common problems
- "I protected it but an editor still changed it." Check whether the protection is in warning mode. Also check that the person is not on the permitted list, and that the domain edit option is off.
- A person you want to allow is missing from the list. They need Editor access to the spreadsheet first. Share the file with them as Editor, then return to the protection.
- You locked yourself out. The owner can always edit any protection. If you are not the owner, ask the owner to change it.
- Protections vanish after copying. When someone makes a copy of the spreadsheet, they become its owner and can edit or delete the protections in their copy. Your original is unaffected.
- Import and scripts. Scripts run as the person who runs them. A script run by a blocked person cannot write to protected cells.
Checklist
- Decide which cells people must be able to change.
- Protect everything else, starting at sheet level.
- Use a description for every protection.
- Choose restricted mode for anything that must not change, and warning mode only for reminders.
- Review the Protected sheets & ranges panel whenever you add or remove editors.
Exercise
You share a budget spreadsheet with a colleague as Editor. You protect the sheet "Budget" with "Restrict who can edit this range" and list only yourself. Your colleague can still read every value in the sheet and can make a copy of the whole spreadsheet. Why is that, and what should you do if the figures must be confidential?
Show answer
Protection only limits editing. Anyone with at least Viewer access can read all cells, and anyone who can view can make a copy (unless the owner turned off downloading, printing and copying for viewers and commenters), and the copy belongs to them. For confidential figures, keep them in a separate spreadsheet that you do not share with that colleague, and share only the results you want them to see.
Exercise
A cell is covered by a protected sheet that allows Ana and Ben, and by a protected range inside it that allows only Ana. Who can edit that cell, and what happens if Ben tries?
Show answer
Only Ana can edit it. An editor must be allowed by every protection that covers the cell, and the range protection excludes Ben, so his edit is blocked.
Exercise
Write the Apps Script lines that protect the range B2:B10 of the active sheet so that only the person running the script can edit it.
Show answer
const range = SpreadsheetApp.getActiveSheet().getRange('B2:B10'); const protection = range.protect().setDescription('B column - owner only'); protection.addEditor(Session.getEffectiveUser()); protection.removeEditors(protection.getEditors());