Run Data Cleaning Tasks with Apps Script Menus
Custom menus in Google Sheets let you run Apps Script tasks from a familiar interface. You can add menu items for actions such as trimming text, standardising columns, generating review sheets or running validation checks, without asking users to edit scripts directly.
Create a Custom Menu
Use the onOpen trigger to add a menu when the spreadsheet opens. Each menu item calls a function in your script.
function onOpen() {
SpreadsheetApp.getUi()
.createMenu("Data tools")
.addItem("Trim selected column", "trimSelectedColumn")
.addItem("Build review sheet", "buildReviewSheet")
.addToUi();
}
function trimSelectedColumn() {
var range = SpreadsheetApp.getActiveRange();
var values = range.getValues().map(function (row) {
return row.map(function (cell) { return typeof cell === "string" ? cell.trim().replace(/\s+/g, " ") : cell; });
});
range.setValues(values);
}
Test menu actions on a copy of your data and write outputs to separate ranges or sheets when changes are hard to reverse.
Useful Task Patterns
- Standardise: trim whitespace, normalise case, remove unwanted characters or apply mapping rules.
- Validate: flag missing values, invalid formats or duplicates in a helper column.
- Review: copy selected rows into a review sheet with status columns.
- Export or prepare: generate a cleaned output range for downstream use.
Using Flookup Alongside Scripts
For many cleaning tasks, formulas can be easier to audit than menu-driven scripts. Flookup custom functions provide in-sheet operations such as NORMALIZE, FUZZYSIM, FLOOKUP, DEDUPE and ULIST. The Sheets AI Assistant can help suggest formulas, and Data Cleaning Automation can run supported batch jobs on a schedule without a custom trigger script.