Sub topic 5
Showing a warning instead of blocking edits
Warning-only protection lets people edit a range after they confirm a prompt. This chapter covers how it differs from restricted protection, how to set it in the interface and in Apps Script, and where it fails. It assumes you can already protect a range from the Data menu and understand the viewer, commenter and editor access levels.
What warning-only protection does
A normal protection has an editor list. People on the list can change the range. Everyone else is blocked. A warning-only protection has no such list. Anyone who already has edit access to the file can change the range, but Sheets first shows a dialog:
> Warning: You are editing part of this sheet that should not be changed. Edit anyway?
The editor clicks OK to continue or Cancel to undo the change.
The prompt is a speed bump. It does not stop anyone. It asks the person to confirm that they meant to touch those cells.
| Property | Restricted protection | Warning-only protection |
|---|---|---|
| Who can edit | Only people on the protection's editor list, plus the file owner | Every person with edit access to the file |
| What others see | An error and the edit is rejected | A confirmation dialog, then the edit proceeds |
| Editor list | Yes | None |
| Good for | Values that must not change | Values that should rarely change |
| Viewers and commenters | Cannot edit (file access) | Cannot edit (file access) |
Neither kind of protection gives extra rights. A viewer or commenter cannot edit a range just because it is warning-only. File access is checked first.
When a warning is the right choice
Use a warning when a mistake is plausible but the cells are not secret or critical:
- Formula columns that people might overwrite by typing a value over the formula.
- Lookup tables that an occasional editor needs to correct.
- Totals rows and calculated fields.
- Templates where the owner wants collaborators to think before changing the structure.
Use restricted protection when a wrong value has real cost, such as pricing inputs, approval flags, or payroll figures. A warning protects against accidents. It does not protect against someone who clicks through.
Warning-only is also useful when no one person should own the range. A restricted protection needs a named editor list, and you have to maintain it as people join or leave. A warning protection has nothing to maintain.
Setting a warning in the interface
- Open the spreadsheet and select the range, for example
D2:D100. - Choose Data > Protect sheets and ranges. The side panel opens.
- Click Add a sheet or range if the panel shows an existing list. The range you selected is filled in.
- Enter a description, such as "Calculated column". Descriptions matter later when you audit protections.
- Click Set permissions.
- Under Range editing permissions, choose Show a warning when editing this range.
- Click Done.
The same dialog offers Restrict who can edit this range. Switching between the two options changes the type of the protection. If you switch an existing restricted protection to warning-only, the editor list is no longer used.
A protected range is shown with a faint diagonal pattern in warning-only mode only on some views, so do not rely on spotting it visually. The side panel is the reliable list.
What the editor experiences
When someone types in a warning-protected cell, the dialog appears before the change is committed. Several behaviors are worth knowing:
- The prompt appears once per edit action. Pasting into 50 protected cells in one paste gives one prompt, not 50.
- If the person cancels, the cell keeps its old value.
- If the person confirms, the edit is saved in version history like any other edit. You can recover the earlier value from there.
- Editors who dismiss the prompt many times still see it again on the next edit. Sheets does not remember an "I understand" choice.
- Clearing or deleting content from the range also triggers the prompt.
Deleting a row or column that crosses a warning-protected range triggers a prompt too in the interface. In that case the range itself shifts or shrinks. Check afterwards that the protection still covers what you intended.
Warning-only with Apps Script
In Apps Script, setWarningOnly(true) on a Protection object creates the warning behavior.
function warnOnEdit() {
const range = SpreadsheetApp.getActiveSheet().getRange('D2:D100');
range.protect()
.setDescription('Calculated column')
.setWarningOnly(true);
}Each call to range.protect() creates a new protection, so running this function twice creates two overlapping protections on D2:D100. To keep the script safe to rerun, look for an existing one by description first:
function ensureWarningProtection() {
const sheet = SpreadsheetApp.getActiveSheet();
const description = 'Calculated column';
const existing = sheet
.getProtections(SpreadsheetApp.ProtectionType.RANGE)
.filter(p => p.getDescription() === description);
if (existing.length > 0) {
return; // Already protected.
}
sheet.getRange('D2:D100')
.protect()
.setDescription(description)
.setWarningOnly(true);
}You can read the setting back with isWarningOnly(), which returns true or false. This is the method the audit function in a later chapter uses to report each protection's mode.
The order of calls matters for editor lists
When setWarningOnly(true) is on, the editor list is ignored. If you later call setWarningOnly(false), the protection becomes restricted again and uses whatever editor list it has. A newly created protection starts with the file's editors and the owner on that list. If you convert a warning protection to a restricted one, set the editors explicitly:
function makeRestricted(description) {
const sheet = SpreadsheetApp.getActiveSheet();
sheet.getProtections(SpreadsheetApp.ProtectionType.RANGE).forEach(p => {
if (p.getDescription() !== description || !p.canEdit()) {
return;
}
p.setWarningOnly(false);
p.removeEditors(p.getEditors());
p.addEditor(Session.getEffectiveUser());
});
}The call to canEdit() skips protections that the current user is not allowed to modify. Calling modifying methods on those would throw an exception.
Warning-only in the Sheets API
In the Sheets API, the same setting is the warningOnly field of a ProtectedRange. Set it to true and leave out the editors field:
{
"requests": [
{
"addProtectedRange": {
"protectedRange": {
"range": {
"sheetId": 0,
"startRowIndex": 1,
"endRowIndex": 100,
"startColumnIndex": 3,
"endColumnIndex": 4
},
"description": "Calculated column",
"warningOnly": true
}
}
}
]
}Row and column indexes are zero-based, and end indexes are exclusive. So startRowIndex: 1, endRowIndex: 100 covers rows 2 through 100, and column index 3 is column D. Compare this to D2:D100 in A1 notation to confirm the offsets.
The API rejects a request that sets warningOnly: true together with an editors list in some cases, and ignores it in others. Do not depend on either behavior. Send one or the other.
How the prompt is decided
The flow below shows what happens when a person edits a protected cell.
Edge cases and common errors
The warning does not apply to the owner differently
The file owner sees the same dialog as other editors on a warning-only range. The owner is not exempt from the prompt, but the owner can always change or remove the protection itself.
Scripts do not see the prompt
A script that writes with setValue or setValues is not asked to confirm. The dialog is for people working in the interface. If your script runs as a user who has edit access, it writes straight through a warning-only range. For a restricted range, the script is blocked only if it runs as someone not on the editor list. Scripts running as the owner or a listed editor can write.
This is the most common surprise. A warning protects against interactive mistakes. It does not make a range safe from automation.
Overlapping protections
If a cell is covered by two protections, one warning-only and one restricted, the restricted one still blocks users who are not on its list. Overlap does not produce a weaker result. You can have a warning-only protection on a whole sheet with a restricted protection on a smaller range inside it. Users see the strictest rule that applies to the cell they edit.
Warning-only on a whole sheet
You can also set warning-only on a sheet protection. The prompt then appears for any edit on that sheet, except cells listed as unprotected ranges. This makes sense for reference sheets that are rarely changed. On a heavily edited sheet, the constant prompts train people to click through without reading, which defeats the purpose.
Prompt fatigue
Warning dialogs work only when they are rare. If a range is edited several times a day by legitimate users, the warning becomes noise. Either move the legitimate inputs out of the protected range, or switch to restricted protection and give the regular editors access.
Copying and importing
Copying a sheet within the file keeps its protections. Copying a protected range's values to another spreadsheet does not carry the protection. Someone with edit access can also copy the whole file if they have permission to make copies, and the copy has no restriction on the original's contents. A warning does not stop this.
Choosing between the two modes
Ask these questions in order:
- Would a wrong value cause real harm? If yes, use restricted protection.
- Is there a stable, small group that should edit the range? If yes, restricted protection with that group is easy to maintain.
- Are the cells edited by many people, but only occasionally and deliberately? Use a warning.
- Are the cells normally changed only by formulas or scripts? A warning catches humans who type over them.
Many sheets combine both. A pricing table is restricted to the finance team. A calculated column that the whole team can see is warning-only. The input cells are left unprotected.
Summary of the key points
- Warning-only protection shows a confirmation dialog and then allows the edit.
- It applies to everyone with edit access, including the owner. It has no editor list.
- Viewers and commenters still cannot edit.
- In Apps Script, use
setWarningOnly(true). In the Sheets API, usewarningOnly: trueand omiteditors. - Scripts are not prompted. A warning does not protect against automation or against deliberate edits.
- Use it for formula columns and rarely changed reference data, and use restricted protection for anything that carries real risk.
Exercise
A teammate has edit access to a spreadsheet. A column of formulas in F2:F200 is protected as warning-only. A script that runs as that teammate calls setValue on F10. What happens, and what should you change if the formulas must not be overwritten by that script?
Show answer
The write succeeds with no prompt, because the confirmation dialog appears only for people editing in the interface and the teammate has edit access. To prevent it, switch the range to restricted protection (setWarningOnly(false)), remove the teammate from the editor list so only the intended users remain, and run the script as a user who is not on that list. Because scripts running as the owner or a listed editor can still write, also check who the script runs as.
Exercise
Write the Apps Script call chain that protects B2:B50 on the active sheet with the description "Lookup table" in warning-only mode. Then say what two things you would check to make sure running the function twice does not create duplicates.
Show answer
SpreadsheetApp.getActiveSheet().getRange('B2:B50').protect().setDescription('Lookup table').setWarningOnly(true); To avoid duplicates, first call sheet.getProtections(SpreadsheetApp.ProtectionType.RANGE) and check whether any protection already has the description "Lookup table" (using getDescription()), and return early if one does. You can also compare getRange().getA1Notation() with 'B2:B50' so that an unrelated protection with the same description does not hide the need for a new one.
Exercise
In the Sheets API, which startRowIndex, endRowIndex, startColumnIndex and endColumnIndex values describe C5:E10, and which field makes the protection warning-only?
Show answer
startRowIndex: 4, endRowIndex: 10, startColumnIndex: 2, endColumnIndex: 5. Start indexes are zero-based and end indexes are exclusive, so row 5 is index 4, row 10 ends at 10, column C is index 2, and column E ends at 5. Set warningOnly: true in the protectedRange object and omit editors.