Blog / Build with AI /

AI for spreadsheets: formulas, scripts and clean-ups

Most spreadsheet pain is not maths. It’s remembering the syntax. You know what you want (“take the first word of this cell, but only if the next column says Yes”) and you don’t remember how to say it in formula language.

That’s exactly the kind of translation an AI assistant is good at. You describe the result in English and it writes the formula. Spreadsheets are also one of the safest places to start building with AI, because you can see the output next to the input and check it with your own eyes.

Here’s how to use it well, and where to be careful.

The basic move: describe the data, then the result

AI can’t see your sheet unless you tell it what’s in it. Most bad formulas come from skipping that step.

A weak request:

Write a formula to combine names.

A strong one:

In Google Sheets, column A has first names, column B has last names. Some rows have a blank first name. Write a formula for column C that gives “Last, First” and, when the first name is blank, just the last name. Start at row 2.

Notice what the second one gives the AI: the tool (Sheets or Excel, because functions differ), the columns, the edge case, and the starting row. You’ll get something like:

=IF(A2="", B2, B2 & ", " & A2)

Short, readable, and checkable. Paste it into one cell, check three rows by hand, then fill down.

Five jobs AI does well in a spreadsheet

1. Clean up messy text

Real-world data comes with extra spaces, odd capitalisation and invisible characters. Ask for:

Column A has product names with random extra spaces and mixed capital letters. Give me a Google Sheets formula that trims the spaces and makes each word start with a capital letter.

The answer should be close to =PROPER(TRIM(A2)). Add CLEAN() as well if the text was copied from a PDF or web page and has hidden characters.

2. Split and extract

Splitting “Lagos, Nigeria” into two columns, or pulling a number out of “Order #48213 – paid”, takes functions like SPLIT, REGEXEXTRACT or Excel’s text functions. Describe an example input and the exact output you want:

Input: Order #48213 - paid. Output: 48213. Google Sheets formula for column A, please.

Giving one worked example is the fastest way to a correct formula. I wrote about this habit in giving AI examples: the fastest way to better output.

3. Find duplicates and problems

Ask for a helper column that flags repeats:

=IF(COUNTIF($A$2:A2, A2)>1, "duplicate", "")

That marks the second and later occurrences, so the first stays unmarked. I covered more patterns in spotting duplicates with AI-written formulas.

4. Lookups and joins

Matching a list of URLs to their titles, or SKUs to costs from another sheet, uses VLOOKUP, XLOOKUP or INDEX/MATCH. These are classic places for off-by-one mistakes, so ask the AI to explain each argument. Then test with one value you know the answer to.

5. Reshaping and summarising

Questions like “How many rows per category?” or “Sum by month” are formulas (COUNTIF, SUMIF) or a pivot table. Ask the AI which is better for your case. Often it’s a pivot table, and it’ll walk you through the steps.

Scripts, when formulas run out

When the job is too big or too repetitive for formulas (reformat 40 sheets, email a summary every Monday, move rows between tabs), AI can draft a script. In Google Sheets that’s Apps Script, which is JavaScript. In Excel it’s VBA, or newer Office Scripts.

A good prompt:

Write a Google Apps Script that looks at the “Orders” sheet, finds rows where column D says “Open”, and moves them to a sheet called “Open orders”. Do not delete anything from the original sheet. Explain how to run it.

Two rules for scripts:

  1. Work on a copy of the file the first time.
  2. Avoid anything that deletes. Ask for scripts that copy or flag, so a mistake costs you nothing.

I’ll look at Apps Script in more depth in a separate post.

Clean-ups: a workflow that doesn’t wreck your data

Cleaning a big messy sheet is where people get burnt, because one wrong “fix all” damages everything. Use this order:

  1. Duplicate the sheet. Work on the copy.
  2. Look first. Ask the AI to suggest what to check: blank cells, inconsistent spellings, mixed date formats, numbers stored as text.
  3. Add helper columns with formulas rather than overwriting the original column.
  4. Spot-check. Pick ten rows, including strange ones, and verify by hand.
  5. Only then copy the helper column and paste it as values over the original, if you want to.

That keeps the original data intact until you’re sure.

Don’t paste sensitive data into a chat

You rarely need to share your real data. Share the structure and a few made-up rows: “Column A has email addresses like name@example.com”. Customer lists, payroll, and client data should not go into a public AI tool. That’s both a privacy rule and a good habit, because made-up examples are enough for formulas.

Where AI gets spreadsheets wrong

  • Mixing up apps. A formula for Excel may not work in Sheets, and vice versa. Always state which one.
  • Wrong separators. Some regional settings use semicolons rather than commas in formulas. If a correct-looking formula throws a parse error, check this first.
  • Silent mistakes. The formula works but answers a slightly different question: counting blanks as zeros, or matching “Lagos” with “Lagos ” (note the space).
  • Invented functions. Rare for common ones, but possible for obscure ones.
  • Confident arithmetic. If you paste numbers into chat and ask the AI to add them up, don’t trust the result. Language models are not calculators. Have the sheet do the calculation, and use the AI to write the formula.

That last point is the one to remember: use the AI for the formula, use the spreadsheet for the answer.

A tidy template for your prompts

Keep this and fill in the gaps:

App: (Google Sheets / Excel)
My data: (what’s in each column, with 2–3 example rows)
What I want: (the result, in plain words)
Edge cases: (blanks, duplicates, odd formats)
Output: (a formula for column X starting at row 2 / a script / a step-by-step)
Also: explain how it works in plain English, and tell me how to test it.

The last line is the one that makes you better at spreadsheets over time, not just faster.

Key takeaways

  • Describe the data and the result. Name the app, the columns and the edge cases.
  • Give one worked example of input and output.
  • Test on a few rows before filling down the whole column.
  • Work on a copy and use helper columns instead of overwriting.
  • Let the spreadsheet do the sums, not the AI.
  • Keep real personal data out of chats. Fake examples are enough.

FAQ

Can AI build a whole spreadsheet for me?

It can draft a structure, a template and the formulas. Treat it as a first draft and test it with real values.

Do I need to know formulas already?

No, but learn what the formula does as you go. Ask for an explanation each time.

Is it better to use a formula or a script?

Formulas for anything that updates live in the sheet. Scripts for repeated tasks, bulk changes and actions outside the sheet, such as sending an email.

Which spreadsheet task do you dread most? Describe it to an AI in three sentences, with one example row, and see what comes back.