Templates, guides & honest tool reviews for small business

Sunday, November 29, 2026

ChatGPT and Google Apps Script: Automate a Sheet Without Coding

ChatGPT and Apps Script - explanatory illustration for chatgpt google apps script
Illustration: ChatGPT and Apps Script

Section: AI Automation

You can get ChatGPT to write Google Apps Script for your spreadsheet, but generated code must be reviewed before it runs. Describe the sheet, say what should happen and where the output goes, and the assistant returns a short script. You then paste it into the script editor that Google builds into every Sheet, run it once, and approve only the access the reviewed script genuinely needs. This guide covers the prompt structure that works, where to paste the code, how to test it without risking your data, and the jobs where a formula is still the better answer. The sample sheet is made up.

What Apps Script adds to a spreadsheet

Formulas calculate values. Apps Script, which is Google's scripting tool inside Sheets, can also do things formulas cannot: add a custom menu, show a dialog, send an email, create a calendar event, copy rows to an archive sheet on a schedule, or build a report file. Google's own documentation describes it as a way to extend Sheets with custom menus, dialogs, sidebars and functions, working with the sheet as a grid of values. None of that requires you to write the code yourself if you can describe the job clearly.

The prompt structure that works

A vague request gets vague code. Give the assistant five things and you give a reviewer a clearer specification:

  • The sheet names and what each one holds, such as Orders and Archive.
  • The exact columns, with their letters and what is in them.
  • The trigger: run when I choose a menu item, run once a day, or run when a form is submitted.
  • The rule, in plain words: copy rows where column E says Closed to Archive without changing Orders.
  • The output: where the result goes, and what should happen to the original row. Start with copy-only behaviour rather than deletion.

Add one sentence about what should happen when something goes wrong, such as "if the Archive sheet is missing, create it". That makes the requested behaviour clearer; it does not guarantee correct code.

Prompt specification - explanatory illustration for chatgpt google apps script
Prompt specification (explanatory illustration, not a software screenshot).

A sample prompt

Here is a complete request you can adapt:

"I have a Google Sheet with two tabs, Orders and Archive. Orders has headers in row 1: A Date, B Order ID, C Customer, D Amount, E Status. Write an Apps Script function called archiveClosed that copies every row where Status is Closed to the Archive tab, keeps the same column order, but does not delete or change Orders. Add a dry-run summary before any copying, and prevent duplicate archive copies by Order ID. Add a custom menu called Orders with an item Archive closed orders that runs the function. If the Archive tab does not exist, create it with the same headers. Show a message at the end with how many rows were moved."

That prompt names the tabs, the columns, the rule, the trigger and the output. It also says what to do when the tab is missing, which is the detail most first attempts leave out.

Paste it into the script editor

  1. Open the spreadsheet and choose Extensions, then Apps Script. A new tab opens with a code editor.
  2. Delete the placeholder function and paste the script ChatGPT gave you.
  3. Click the save icon and give the project a name.
  4. Choose the function name from the dropdown at the top and click Run.
  5. Google asks for permission the first time. Read the permissions. Stop if they exceed the task, and have the code reviewed rather than approving automatically.

The authorization step is normal. A script that reads and writes your sheet has to be allowed to do so, but it is not a safety certificate. Pasted code can send data elsewhere; review services, external requests and deletion operations before granting access.

Review before running - explanatory illustration for chatgpt google apps script
Review before running (explanatory illustration, not a software screenshot).

Test on a copy first

Before you run anything that deletes rows, make a copy of the file with File, then Make a copy, and run the script there. Check three things: the intended rows were copied, the columns stayed in the same order, and nothing else changed. A script that deletes is much harder to undo than a formula that shows a wrong number, so the copy is not optional for destructive jobs.

When it does not work

Paste the error message back into the chat with one line of context. The usual failures are a tab name that does not match exactly, a header in a different row, or a column letter that shifted. Ask for the corrected function only, not the whole explanation, and keep the conversation in one thread so the assistant remembers the sheet layout. Re-test each revision. Do not assume an error-free run proves the output is correct.

How this fits a small business

Most small teams do not need a system. They need the same three jobs done every week without anyone remembering to do them: move the finished rows out of the working sheet, send the summary, file the copy. Each of those is a short script, and together they remove the hour of copy and paste that nobody enjoys. If you are already using chat assistants for formulas, this is the next step, and our overview of AI automation for small businesses sets out which jobs to hand over first. If you would rather stay inside Excel and formulas, the ideas in Excel automation tips cover that route.

Copy-only script test - explanatory illustration for chatgpt google apps script
Copy-only script test (explanatory illustration, not a software screenshot).

Good first automations

  • Archive closed rows to a second tab and clear them from the working sheet.
  • Add a menu that formats the current sheet as a report: widths, bold headers, frozen row.
  • Email a summary of the day's new rows to one address, on a daily trigger.
  • Create a PDF of a chosen range and save it to Drive with a dated file name.
  • Add a sidebar with a few buttons that run the jobs you use most.

Each of these is a small, well defined job, which is exactly what a language model handles well. Larger projects, such as a full order system, need a person who can read the code.

Limits and safety

A manually run bound script normally runs as the current user within its authorized scopes. An installable trigger runs as the account that created the trigger. Limit scopes to what the task needs; authorization is not blanket access to every account resource. That is why you review what it does before running it, and why you never paste passwords, API keys or private customer data into a chat window to get code written. Google also applies usage quotas to scripts, so a job that runs every minute may stop working; daily or on-demand triggers are safer. If the script will handle personal data, check with whoever owns that data before you automate it.

Script safeguards - explanatory illustration for chatgpt google apps script
Script safeguards (explanatory illustration, not a software screenshot).

When a formula is better

If the job is "show the total for each region", a formula or a PivotTable is faster to build, easier to audit and generally easier to review than a script with side effects. If the job is "change the sheet itself", such as deleting rows, creating files or sending email, that is when a script earns its place. For data that arrives as a file every month, Power Query or an import function is usually better than a script, and our guide to IMPORTDATA covers the simple case.

Questions and answers

Do I need to know JavaScript?

No, but you do need to read the code well enough to see which sheet and which columns it touches. If you cannot tell, ask the assistant to explain it in one paragraph before you run it.

Is Apps Script free?

Yes, it comes with a Google account and a Google Sheet. Google applies account- and service-specific quotas; check the current limits for the intended workload.

Can ChatGPT run the script for me?

This workflow uses ChatGPT to draft code, not execute it. You or a qualified reviewer inspect it, then run it in Apps Script with suitable permissions. Other connected execution setups are outside this tutorial.

Will the script keep working when I close the sheet?

On-demand functions run when you choose the menu item. Time based triggers run on Google's servers, so they keep going without the file open.

What if the script breaks after a Google update?

Keep the prompt and the working version somewhere you can find them. Paste the error back into the chat and ask for a fix. Keep test cases and review each repair before rerunning it.

Official references

العربية