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
- Menu name
Helpful toolsThis is the menu label shown beside the standard Sheet menus.
- Menu item name
Show selected cellThis is the action editors choose from the menu.
- Message text
You selectedChange 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.
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
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.
Save both functions
Keep onOpen and showSelectedCell together because the menu calls the second function by name.
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
Apps Script symbols
Service pages
Keep going
Related tasks, basics, and apps
- Task guide Send an email for each row in a Google Sheet
Use one row per person, then let the script send only the rows that have not already been marked as sent.
- Task guide Create a Google Doc from each Sheet row
Keep a person and a project note in a Sheet, then create one short Doc per unfinished row.
- Object reference Spreadsheet
A Spreadsheet is the whole Google Sheets file. Use SpreadsheetApp.getActiveSpreadsheet() or openById() to get it, then call getSheetByName() or getActiveSheet().
- Object reference Sheet
A Sheet is one tab inside a Google spreadsheet. Reach it with getSheetByName() or getActiveSheet(), then inspect getLastRow() or read cells with getRange().
- Object reference Range
A Range represents one cell such as A2 or a rectangular block of rows and columns in a Sheet. Use getValue() for one cell and getValues() or setValues() for a 2D array of rows.
- Basics Run your first Apps Script function
Open Extensions > Apps Script from a Google Sheet or Doc to reach the code editor. Replace the starter function myFunction() { }, save with Ctrl+S, press Run, and read what Logger.log printed.
- Basics Bound scripts and standalone scripts
Every Apps Script project is either attached to one Google file or standing on its own. The choice decides how your code reaches your data, who can see it, and where you find it later.
- Google app Google Sheets
SpreadsheetApp lets a Google Sheets script read a Sheet or Range, add a custom menu or formula, and run repeatable actions across rows.