Skip to content

No account required

Start a project

Google Apps Script generator

Describe what the script should do. You get a complete function, written to survive the execution limit.

Plain English. The way you would explain it to a colleague.

Optional, and the single biggest difference between a usable answer and a generic one.

A worked example

Trim the spaces off every text cell in Sheet1

function trimAllCells() {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
  const range = sheet.getDataRange();
  const values = range.getValues();

  const trimmed = values.map(function (row) {
    return row.map(function (cell) {
      return typeof cell === 'string' ? cell.trim() : cell;
    });
  });

  range.setValues(trimmed);
}

It pulls the whole used range into memory in one call, trims anything that is a string, and writes the whole block back in one call. Numbers and dates pass through untouched, which matters because turning a date into text is not a repair.

What it assumes

  • Overwrites the range in place. There is no undo inside the script, so run it on a copy of the sheet first.
  • Formulas are replaced by their current values, because getValues returns results rather than formulas. Use getFormulas as well if the sheet has any.
  • Asks for permission to manage your spreadsheets on the first run. That prompt is Google's, not ours.

01

It reads and writes in one go.

Touching cells one at a time is the single reason these scripts hit the six minute limit. Ranges come back with getValues, are changed in memory, and go back with setValues.

02

It tells you what it will ask permission for.

The first run shows an authorisation screen naming what the script can reach. Knowing which scope it needs before you see that screen is the difference between approving it and abandoning it.

03

It is a complete function.

Not a fragment to assemble. Paste it into the editor, pick it from the run menu, and it works or it tells you why.

Questions people ask

Where does this code go?

In your sheet, open Extensions and then Apps Script. Paste the function into the editor, save, then pick it from the function dropdown and press Run.

Why does it want permission to access my spreadsheets?

Because it edits one. Apps Script runs as you, so Google asks you to approve the scopes the code uses. Read what the prompt names before approving it, exactly as you would for any add-on.

My script times out. Why?

Almost always because it reads or writes cells one at a time. Apps Script stops a function after six minutes on a consumer account, and a per-cell loop over a few thousand rows will reach it. The code here batches for that reason.

Can it send email or work on a schedule?

Yes. Describe that and you will get the MailApp or trigger code with it, along with the daily quota that applies to your account type.

When it is a whole file

A formula fixes one column. If what you actually have is four exports and a question, drop them here and you get the cleaned data, the analysis and the charts back.

No account needed to start. You only pay when you like what you see.