You have a Google Sheets script with an onEdit(e) trigger that changes the value of cell B1 whenever any cell in column A is edited.
If you edit cell A2, what will be the value of B1 after the script runs?
function onEdit(e) {
var sheet = e.source.getActiveSheet();
var range = e.range;
if (range.getColumn() == 1) { // column A
sheet.getRange('B1').setValue('Edited');
}
}Think about what the script does when a cell in column A is edited.
The script checks if the edited cell is in column A. If yes, it sets B1 to 'Edited'. So after editing A2, B1 will show 'Edited'.
You want to run a script automatically every time your Google Sheets file is opened. Which function name should you use?
Think about the trigger that activates when the file opens.
The onOpen() function runs automatically when the spreadsheet is opened. The others run on different events.
You wrote an onEdit(e) trigger that changes cell B1 whenever any cell in column B is edited. But when you edit B2, the script runs repeatedly and freezes your sheet.
Why does this happen?
function onEdit(e) {
var sheet = e.source.getActiveSheet();
var range = e.range;
if (range.getColumn() == 2) { // column B
sheet.getRange('B1').setValue('Updated');
}
}Think about what happens when the script edits a cell inside onEdit.
The script edits B1 inside onEdit. Editing B1 triggers onEdit again, causing the script to run repeatedly and freeze the sheet.
In an onEdit(e) trigger, you want to find the address of the edited cell to log it.
Which expression gives the correct cell address (like 'B3')?
Check the event object properties for the edited range.
e.range.getA1Notation() returns the address of the edited cell like 'B3'. The others do not return the cell address correctly.
Simple triggers like onEdit(e) run automatically but have restrictions. Which is a key reason to use installable triggers instead?
Think about what simple triggers cannot do due to security limits.
Simple triggers cannot access services that require user authorization. Installable triggers can, allowing more powerful scripts.