Skip to content

Task guide

Add a custom menu to a Google Sheet

Use an onOpen() simple trigger and SpreadsheetApp.getUi().createMenu() to add a custom menu bar item that shows which cell is currently selected.

1 · Prepare

Put these pieces in place

  • Start from the Google Sheet where you want the menu to appear.
  • Open the script from that Sheet by choosing Extensions and then Apps Script.
  • Plan for editors to refresh the Sheet after you save the script.

Change these values

Change these values

Make the code yours before you run it.
Menu name
Helpful tools

This is the menu label shown beside the standard Sheet menus.

Menu item name
Show selected cell

This is the action editors choose from the menu.

Message text
You selected

Change it if you want the alert to use different words.

2 · Review before running

What the script can access and change

Permissions you approve

  • Show a custom menu and alert inside the current Google Sheet.

Effects of one run

  • Adds a Helpful tools menu whenever an editor opens the Sheet.
  • Shows the active cell and tab name without changing Sheet data.

3 · Copy

Paste this into the Apps Script editor

Create or open a script file, replace the example values marked above, then save the project.

Code.gs
const MENU_NAME = 'Helpful tools'; // This is the menu label shown beside the standard Sheet menus.
const MENU_ITEM_NAME = 'Show selected cell'; // This is the action editors choose from the menu.
const MESSAGE_TEXT = 'You selected'; // Change it if you want the alert to use different words.

function onOpen() {
  SpreadsheetApp.getUi()
    .createMenu(MENU_NAME)
    .addItem(MENU_ITEM_NAME, 'showSelectedCell')
    .addToUi();
}

function showSelectedCell() {
  const range = SpreadsheetApp.getActiveRange();
  if (!range) throw new Error('Select a cell before using ' + MENU_NAME + '.');
  const message = MESSAGE_TEXT + ' ' + range.getA1Notation() + ' on the ' + range.getSheet().getName() + ' tab.';
  SpreadsheetApp.getUi().alert(message);
}

4 · Run safely

Follow these steps in order

  1. Use the Sheet-bound script

    Open Apps Script from the Sheet, not from a separate script project, so the menu knows which spreadsheet to use.

  2. Save both functions

    Keep onOpen and showSelectedCell together because the menu calls the second function by name.

  3. Refresh the Sheet

    Reload the Sheet. Choose Helpful tools and then Show selected cell to try it.

5 · Confirm

How to tell it worked

After refreshing the Sheet, Helpful tools appears in the menu bar and its item displays the selected cell.

If the result is different

Troubleshooting

The menu is missing.
Save the script and refresh the spreadsheet tab. Make sure the function is named onOpen exactly.
The item shows an error.
Make sure showSelectedCell is present with the same spelling used in addItem.

Technical details

Names used in this script

Open these details when you want to adapt the example or look up an exact service or method name.

Show Apps Script symbols and service pages

Keep going