Sub topic 11
Designing a protection scheme for a shared spreadsheet
This chapter assumes you can protect a range and a sheet in the interface, that you know the difference between viewer, commenter, and editor access, and that you can read short Apps Script functions. It pulls those pieces together into a repeatable design process. You will plan a scheme before you click anything, build it, and review it over time.
Start from the failure you want to prevent
A protection scheme is a set of answers to one question: what mistake or misuse costs us the most? Protection restricts edits to cells and sheets. It does not hide data, and it does not stop someone with edit access to the file from copying the data elsewhere. Design around accidental damage and unauthorized changes, not secrecy.
Typical failures, and the protection that answers each:
| Failure | Likely cause | Protection response |
|---|---|---|
| A formula column is overwritten with a typed value | Someone pastes over it | Warning-only protection on the column |
| Header names change and a script or chart breaks | Someone renames a header | Restricted protection on the header row |
| Rates or thresholds are altered without approval | Any editor can type in the cell | Restricted protection, with a short editor list |
| A form-style sheet is rearranged by users | Users insert rows, delete columns, or edit labels | Whole-sheet protection with unprotected input ranges |
If you cannot name the failure a protection prevents, do not add it. Each protection is something you will have to explain, maintain, and eventually audit.
Classify the spreadsheet's regions
Walk through each sheet and sort every region into one of four classes.
- Inputs. Cells people are meant to type in. Leave these editable.
- Calculations. Formulas and derived values. People rarely need to edit them.
- Configuration. Rates, lookup tables, named lists, and anything else that changes the meaning of the results.
- Structure. Headers, labels, frozen rows, and the layout that scripts, charts, and pivot tables depend on.
Then pick the strength of protection for each class:
| Region class | Typical choice | Reason |
|---|---|---|
| Inputs | None, or an unprotected exception | They must stay easy to edit |
| Calculations | Warning-only, or restricted | Overwrites are usually accidents, so a prompt may be enough |
| Configuration | Restricted to named editors | Changes alter results and should be deliberate |
| Structure | Restricted | Breakage here affects everything downstream |
Choose between range protections and sheet protection
Both approaches can produce the same result, but they fail differently.
- Protect the sheet, then add unprotected exceptions. Everything is locked by default. New rows, columns, and cells that you add later are covered automatically. This suits input forms and report sheets. The risk is the opposite one: users get blocked from legitimate edits, and the owner gets requests.
- Protect individual ranges. Everything is open by default, and you lock specific areas. This suits working sheets where most cells are inputs. The risk is gaps. A new calculated column added next month is unprotected until someone remembers to protect it.
A practical rule: if more than half of the sheet is locked, protect the sheet and carve out inputs. Otherwise protect the specific ranges.
Remember that the exception list on a protected sheet is a convenience, not a security boundary. An unprotected range on a protected sheet is editable by anyone who already has edit access to the spreadsheet.
Decide who the protection editors are
For each restricted protection, decide the editor list deliberately.
- Use a small group of named people, such as the spreadsheet's maintainers, rather than the entire organization.
- Prefer one or two owners of the scheme over many individuals. Each extra editor of a protection can also change or remove it.
- Keep a person who is not on holiday and who will not leave the team. A protection whose only editors have left the organization is hard to manage later, because only the file owner can step in.
- Remember that the file owner can always edit protected content. Your scheme cannot restrict the owner.
Anyone you list as a protection editor must also have edit access to the file. Protection narrows who can edit within the group that already has file access. It cannot grant access beyond it. If someone has view or comment access, adding them as a protection editor changes nothing for them.
Use warning-only protection sparingly
Warning-only protection shows a confirmation prompt but still lets the person continue. It is useful for calculated columns, where overwriting is usually a slip. It teaches users that a cell is not meant to be typed in.
Its weakness is habit. If every second range warns, people click through without reading. Reserve warnings for places where a mistake is plausible but a legitimate override is occasionally needed. Use restricted protection when no one outside the editor list should ever change the cells.
Document the scheme inside the file
A scheme that only its author understands will fail the first time that person is away. Every protection has a description field. Use it, and use a consistent format. For example:
Header row - structure - owner: finance-teamRates table - config - owner: j.alvarezTotals column - calc - warning only
Add a short "Read me" sheet that lists:
- What each protected region is for.
- Who to ask for changes.
- Where input cells are, by color or by name.
Giving input cells a consistent background color is a cheap visual guide. Users see at a glance where they may type.
Build the scheme from a script
Once the plan is written, building it with a script makes it repeatable. You can rebuild the scheme on a copy of the sheet, and you can recreate it after someone removes a protection by mistake. The following function defines the scheme as data and then applies it. It first removes the protections it created earlier, identified by a description prefix, so running it twice does not produce duplicates.
const SCHEME_PREFIX = 'SCHEME: ';
const SCHEME = [
{ sheet: 'Budget', range: 'A1:E1', note: 'Header row', warningOnly: false },
{ sheet: 'Budget', range: 'F2:F100', note: 'Totals column', warningOnly: true }
];
function applyScheme() {
const ss = SpreadsheetApp.getActive();
const me = Session.getEffectiveUser();
// Remove earlier protections created by this scheme.
ss.getSheets().forEach(sheet => {
sheet.getProtections(SpreadsheetApp.ProtectionType.RANGE).forEach(p => {
if (p.getDescription().indexOf(SCHEME_PREFIX) === 0 && p.canEdit()) {
p.remove();
}
});
});
// Create the protections described by SCHEME.
SCHEME.forEach(item => {
const sheet = ss.getSheetByName(item.sheet);
if (!sheet) {
throw new Error('Sheet not found: ' + item.sheet);
}
const protection = sheet.getRange(item.range).protect()
.setDescription(SCHEME_PREFIX + item.note);
if (item.warningOnly) {
protection.setWarningOnly(true);
} else {
protection.removeEditors(protection.getEditors());
protection.addEditor(me);
if (protection.canDomainEdit()) {
protection.setDomainEdit(false);
}
}
});
}Keep the description prefix stable. The cleanup step relies on it to find only the protections that belong to the scheme, so protections created by hand are never touched.
Because the script runs as the person who triggers it, the editor list for restricted protections contains that person. Run it as the scheme owner, and add other maintainers explicitly with addEditor or addEditors if they need access.
Plan for the limits
Build the plan with the known limits of protection in mind.
- Edit access is still powerful. Anyone with edit access to the file can copy the spreadsheet, and the copy has no protections they cannot override as its new owner. They can also read all the data.
- Protection does not hide. Viewers and editors see protected values. To keep data private, move it to another file and share that file separately.
- Imports and scripts. A formula such as
IMPORTRANGEreads from a source file with its own access rules. Protecting the destination does not protect the source. - Sheet-level actions. Check what your sheet protections allow for deleting, hiding, or reordering tabs, and test with a real editor account instead of assuming.
- Owner bypass. The file owner is never blocked, so ownership transfers matter. When the file moves to a new owner, review the protections.
A common mistake is protecting a sheet and then sharing the data it holds with a wide audience as "read-only." Share with view access. Do not rely on protection to turn editors into viewers.
Test with a second account
Do not trust a protection you have only seen from the owner's account. The owner is never blocked, so everything looks fine from there. Test with at least two accounts:
- An ordinary editor who is not on any protection's editor list. Confirm that restricted ranges refuse the edit, warning-only ranges prompt, and unprotected exceptions accept input.
- A viewer. Confirm they cannot edit anything at all.
Also test the actions people do in bulk: pasting a block that overlaps a protected range, sorting a range that includes a protected cell, and filling down. Mixed selections are where users most often hit unexpected errors, so tell them what the error means and whom to contact.
Review the scheme over time
Schemes drift. People leave, sheets grow, and columns get added. Set a review routine.
- Run an audit function, like the
listProtectionsfunction from earlier in this tutorial, after any structural change. - On a calendar basis, such as quarterly, check that every protection editor is still on the team.
- Look for descriptions that are empty or say "Untitled." Each one should have an owner or be removed.
- Check that new calculated columns are protected.
- Check that any warning-only protection still earns its keep. If users always click through, switch it to restricted or remove it.
- Before transferring file ownership, export the protection list so you can compare afterwards.
Common mistakes
- Protecting everything. Users stop editing, or ask the owner to remove protections, and the scheme collapses.
- Listing everyone as a protection editor. A restriction that includes the whole team does nothing.
- Leaving empty descriptions, which makes audits slow.
- Testing only as the owner.
- Forgetting new columns and rows after structure changes.
- Treating protection as privacy.
Summary of the design process
- Name the failure each protection prevents.
- Sort regions into inputs, calculations, configuration, and structure.
- Choose sheet protection with exceptions, or range protections, based on how much of the sheet is locked.
- Choose restricted or warning-only for each region.
- Name a small, stable editor list.
- Describe every protection consistently.
- Build from a script and test with two accounts.
- Review on a schedule.
Exercise
A team shares a "Quotes" sheet. Column A to C are typed by sales staff, column D is a formula for tax, column E is a formula for the total, and a small table in H1:I5 holds the tax rates. Only the finance lead should change the tax rates. Design a protection scheme and explain your choices.
Show answer
Sort the regions first. A:C are inputs, so leave them unprotected. D and E are calculations that people may overwrite by accident, so use warning-only protection on D2:E1000 (or protect the sheet and leave A:C as exceptions if most of the sheet is locked). H1:I5 is configuration, so use restricted protection with the finance lead as the only editor besides the file owner. Give each protection a description such as "Tax rates - config - owner: finance-lead". Test with an ordinary editor account and a viewer account, because the owner is never blocked. Remember that all editors can still read and copy the tax rates.
Exercise
Why does the applyScheme script remove old protections before creating new ones, and why does it only remove those whose description starts with a fixed prefix?
Show answer
Removing first keeps the script idempotent, so running it twice does not create duplicate protections on the same range. The prefix limits removal to protections that the scheme itself created, so protections that people added by hand for other purposes are left alone.
Exercise
A colleague says, "I protected the Salaries sheet, so only HR can see the numbers." What is wrong with this claim, and what should they do instead?
Show answer
Protection restricts editing, not viewing. Everyone with access to the file can still see the values, and editors can copy the data. To keep salaries private, move them to a separate file shared only with HR, or restrict access to the file itself.