Google Sheets custom menu script builder
Name your menu, list its items and pick what each one does; get the Apps Script, ready to paste. Most custom-menu examples stop at the menu and leave the functions to you. This one writes both, with every item's name matched to its function — the mismatch that makes a menu item say Script function not found.
The script, with the example menu composed on the page, no account, nothing stored
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('Tasks')
.addItem('Sort by due date', 'sortByDue')
.addItem('Mark as done', 'markDone')
.addToUi();
}
function sortByDue() {
SpreadsheetApp.getActiveSheet().getRange('A2:C').sort(3);
}
function markDone() {
const row = SpreadsheetApp.getActiveRange().getRow();
SpreadsheetApp.getActiveSheet().getRange(row, 2).setValue('Done');
}
noteThe menu is built when the file opens, so a change to the script needs a save and a reload before the menu shows it.
noteSorting moves whole rows from column A to column C. Anything to the right of C stays where it is and no longer lines up — set the last column to the table's real last column.
noteMark writes into whichever row the cursor is in, header row included. Undo (Ctrl+Z) reverses it like any edit.
Your menu, item by item
| Tasks → | Runs | Does |
|---|---|---|
| Sort by due date | sortByDue | Sorts rows 2 and down by column C, A→Z / oldest first. Each row moves as a whole, A to C. |
| Mark as done | markDone | Writes “Done” in column B of the row the cursor is in. |
Where it goes
- Open the spreadsheet and click Extensions, then Apps Script. It opens the sheet's own script project in a new tab.
- Delete the starter code and paste the script in.
- Save the project (the disk icon, or Ctrl+S).
- Go back to the sheet and reload the page. Saving does not run onOpen — the Tasks menu appears a few seconds after the reload, after Help.
- Click an item. The first time, Google asks for permission and warns the app isn't verified: Review permissions → Advanced → Go to the project (unsafe) → Select all → Continue. You wrote it; that warning is what every personal script gets.
How the menu is built
A function called onOpen runs by itself when someone who can
edit the spreadsheet opens it. Inside it, createMenu names the
menu, each addItem adds one line — the words you see, then the
name of the function that line runs — and addToUi puts the
menu in the menu bar, after Help.
That is also why a new menu doesn't appear when you save: nothing has
opened the file yet. Reload the page and it shows up a few seconds after
the grid. The first click on an item asks for permission, because the item
runs code that edits your sheet; onOpen on its own needs none.
Seeing it done
The channel builds one on camera in How to Create a Custom Menu in Google Sheets.