0
0
Google Sheetsspreadsheet~10 mins

Creating custom menus in Google Sheets - Formula Evaluation Walkthrough

Choose your learning style9 modes available
Sample Data

A simple list of student names and their scores.

CellValue
A1Name
B1Score
A2Alice
B285
A3Bob
B390
A4Charlie
B478
Formula Trace
function onOpen() { var ui = SpreadsheetApp.getUi(); ui.createMenu('Custom Menu') .addItem('Show Alert', 'showAlert') .addToUi(); } function showAlert() { SpreadsheetApp.getUi().alert('Hello! This is a custom menu alert.'); }
Step 1: var ui = SpreadsheetApp.getUi();
Step 2: ui.createMenu('Custom Menu')
Step 3: ui.createMenu('Custom Menu').addItem('Show Alert', 'showAlert')
Step 4: ui.createMenu('Custom Menu').addItem('Show Alert', 'showAlert').addToUi()
Step 5: function showAlert() { SpreadsheetApp.getUi().alert('Hello! This is a custom menu alert.'); }
Cell Reference Map
  A       B
1 Name    Score
2 Alice   85
3 Bob     90
4 Charlie 78

No cell references are used in the script; it interacts with the UI only.
The script does not reference any cells directly; it creates a menu in the spreadsheet UI.
Result
File
OK
The custom menu named 'Custom Menu' appears in the spreadsheet menu bar. Clicking 'Show Alert' shows a popup alert with a message.
Sheet Trace Quiz - 3 Questions
Test your understanding
What does the function onOpen() do in this script?
ADeletes the default menus
BShows an alert immediately
CCreates a custom menu when the spreadsheet opens
DChanges cell values
Key Result
Creating custom menus uses onOpen() to add menu items linked to functions that run on user clicks.