Sample Data
A simple score table with names and scores.
| Cell | Value |
|---|---|
| A1 | Name |
| B1 | Score |
| A2 | Alice |
| B2 | 85 |
| A3 | Bob |
| B3 | 90 |
| A4 | Charlie |
| B4 | 78 |
Jump into concepts and practice - no test required
A simple score table with names and scores.
| Cell | Value |
|---|---|
| A1 | Name |
| B1 | Score |
| A2 | Alice |
| B2 | 85 |
| A3 | Bob |
| B3 | 90 |
| A4 | Charlie |
| B4 | 78 |
onEdit(e) and onOpen() are Google Sheets triggers that run scripts automatically when you edit a cell or open the spreadsheet.A B C 1 Name Score 2 Alice 88 Updated! 3 Bob 90 4 Charlie 78 Menu: 'My Menu' appears in toolbar
onOpen trigger do in Google Sheets?onOpen trigger runs a script automatically when the spreadsheet is opened by a user.onEdit, which runs on cell changes, onOpen activates only on opening the file.onEdit trigger function in Google Sheets Apps Script?onEdit trigger function must accept an event object parameter e to access edit details.e and braces.onEdit function in Google Sheets Apps Script:function onEdit(e) {
if (e.range.getA1Notation() === 'A1') {
e.source.getActiveSheet().getRange('B1').setValue('Edited!');
}
}A1?e.range.getA1Notation().onOpen function is intended to show a custom menu, but it doesn't work:function onOpen() {
var ui = SpreadsheetApp.getUi;
ui.createMenu('My Menu')
.addItem('Say Hello', 'sayHello')
.addToUi();
}SpreadsheetApp.getUi without parentheses, so it references the function but does not call it.getUi() calls the method and returns the UI object needed to create the menu.onEdit trigger that automatically timestamps column B when a user edits column A in the same row. Which script correctly does this?e.range.getColumn() === 1.setValue(new Date()).