Automate Recurring Cleaning Workflows with Apps Script
Recurring spreadsheet jobs are easier to manage when you package the steps into a reusable workflow: prepare inputs, clean or standardise values, produce a review output and run the same process on a schedule. This guide shows a practical Apps Script pattern for that kind of workflow in Google Sheets.
Design a reusable workflow
Use a consistent sheet structure so each run behaves predictably:
- Input: raw or imported data that changes each run.
- Config: ranges, thresholds, column numbers and output locations.
- Output/Review: cleaned rows, matches, flags or exceptions for review.
- Log: timestamp, rows processed and any errors.
Example Apps Script workflow
The script below reads a source range, applies basic standardisation, writes results to a review sheet and records a run log. You can extend it with lookups, matching logic or calls to other functions.
function runCleaningWorkflow() {
var ss = SpreadsheetApp.getActive();
var input = ss.getSheetByName("Input");
var review = ss.getSheetByName("Review");
var log = ss.getSheetByName("Log");
var values = input.getRange("A2:B").getValues().filter(function (r) { return r[0] || r[1]; });
var output = values.map(function (row) {
var name = String(row[0] || "").trim().replace(/\s+/g, " ");
var id = String(row[1] || "").trim();
return [name, id, name ? name.toLowerCase() : ""];
});
review.getRange("A2:C").clearContent();
if (output.length) review.getRange(2, 1, output.length, output[0].length).setValues(output);
log.appendRow([new Date(), "runCleaningWorkflow", output.length, "complete"]);
}
To run it on a schedule, open Triggers in Apps Script and add a time-driven trigger. Keep runs idempotent where possible by writing to a dedicated output range or review sheet.
Add a review step
Automated workflows are most reliable when uncertain results are reviewed rather than overwritten. For matching jobs, write scores, candidate values and statuses to the review sheet. For standardisation jobs, keep original and cleaned values side by side until the rules are trusted.
Using Flookup for parts of the workflow
Apps Script is flexible, but you may not need custom code for every step. Flookup custom functions can handle in-sheet cleaning, similarity scoring, fuzzy lookup, unique lists and deduplication. Data Cleaning Automation supports scheduled batch runs for supported custom-function jobs, and Data Connectors can bring external records into a staging sheet before review or write-back where supported.