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 menu
Item 1
Item 2 (optional)
Item 3 (optional)
Item 4 (optional)
Item 5 (optional)

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 →RunsDoes
Sort by due datesortByDueSorts rows 2 and down by column C, A→Z / oldest first. Each row moves as a whole, A to C.
Mark as donemarkDoneWrites “Done” in column B of the row the cursor is in.

Where it goes

  1. Open the spreadsheet and click Extensions, then Apps Script. It opens the sheet's own script project in a new tab.
  2. Delete the starter code and paste the script in.
  3. Save the project (the disk icon, or Ctrl+S).
  4. 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.
  5. 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.