Sub topic 5
Showing a warning instead of blocking edits
When warning-only protection fits
This chapter assumes that you can use cells, ranges, and sheet tabs, and that you understand A1 notation. You should also know the difference between viewers, commenters, and editors. Basic JavaScript is useful for the Apps Script example.
A protected range normally prevents most editors from changing its contents. Warning-only protection uses a softer rule. When an editor tries to change the range, Google Sheets shows a confirmation message. The editor can continue after acknowledging the warning.
Use warning-only protection when people should pause and check their action, but they still need the ability to edit. It works well for:
- Formulas that users may occasionally need to replace.
- Shared templates where accidental edits are more likely than malicious edits.
- Review columns that need human judgment.
- Imported or calculated data that should usually remain unchanged.
Use normal restricted protection when only specific people should be able to edit the range.
Enable a warning in the interface
- Open the spreadsheet.
- Select the range, such as
D2:D100. - Select Data > Protect sheets and ranges.
- Confirm the range in the side panel.
- Select Set permissions.
- Choose Only show a warning when editing this range.
- Select Done.
The warning applies to editors who attempt to change the selected cells. A viewer or commenter cannot edit the cells in the first place, so warning-only protection does not change their access.
The protection is attached to the range, not to the value currently in each cell. If you later insert rows or change the layout, review the protected range to confirm that it still covers the intended cells.
Understand the trade-off
Warning-only protection prevents accidental changes only when the editor responds carefully. It does not enforce an approval process, preserve the old value automatically, or stop a determined editor.
| Protection choice | Editor can continue? | Best use |
|---|---|---|
| Restricted protection | No, unless allowed by the protection | Formulas and controlled data |
| Warning-only protection | Yes, after confirmation | Important values that still need occasional edits |
| No protection | Yes, without a prompt | Fully collaborative input areas |
The warning is also not a version-control system. Use version history to recover an earlier value, and use a separate backup or audit process when changes require accountability.
Create a warning with Apps Script
Apps Script is Google’s JavaScript-based automation environment for Workspace. The following function protects D2:D100 on the active sheet and sets the protection to warning-only mode.
function warnOnEdit() {
const range = SpreadsheetApp.getActiveSheet().getRange('D2:D100');
range.protect()
.setDescription('Calculated column')
.setWarningOnly(true);
}To run it, open Extensions > Apps Script, add the function, save the project, and run warnOnEdit. Google may ask you to authorize the script. The function creates a new protection each time it runs, so avoid running it repeatedly unless you intend to create multiple protections.
Apps Script can also inspect the setting:
function listWarningProtections() {
const sheet = SpreadsheetApp.getActiveSheet();
const protections = sheet.getProtections(
SpreadsheetApp.ProtectionType.RANGE
);
protections.forEach(protection => {
Logger.log(
'%s: warningOnly=%s',
protection.getDescription(),
protection.isWarningOnly()
);
});
}A protection with isWarningOnly() equal to true warns instead of restricting the edit. If a protection should become strict, an authorized script can call setWarningOnly(false). That change affects the editing experience immediately, so document the reason and review the allowed editors before making it.
Design a useful warning
A warning is most effective when its scope and description explain the risk. Protect only the cells that need attention, and give the protection a description such as Calculated column or Approved budget.
Before enabling it, test the range as an editor:
- Select a protected cell.
- Change its value.
- Confirm that the warning identifies the protected range.
- Choose Cancel and verify that the value did not change.
- Repeat and choose Continue.
- Verify that the edit is recorded in version history.
Exercise
A shared budget sheet contains formulas in E2:E50, but managers sometimes need to override individual results. Should you use restricted protection or warning-only protection?
Show answer
Use warning-only protection if managers are trusted to override the formulas after reviewing the warning. Use restricted protection if only designated administrators should be able to make overrides.