Guides

Writing Excel Formulas with AI: A Practical Guide

The gap between a formula that works and one that returns #REF! is almost always in the prompt. Here's what a good one contains.

The SheetAI Team5 min readUpdated August 13, 2026
Write Excel formulas with AI: a formula cell connected to the two ranges it reads. Cover image from the SheetAI blog.

Key takeaways

  • Name the ranges, the key column, and what should happen when nothing matches.
  • Ask for the explanation with the formula. Wrong assumptions show up there first.
  • Test on rows where you already know the answer, plus one deliberate edge case.
  • Array behaviour, text-formatted numbers, and links to other files are the usual failure points.

Ask ten people what went wrong with an AI-generated formula and nine describe the same thing. It looked right. They pasted it in. It threw an error, or worse, it returned a number that was quietly wrong. Nearly every one of those failures traces back to something the assistant was never told.

So this guide is mostly about the prompt. What a complete one contains, how to check the result in under a minute, and the specific cases where you should expect to finish the job yourself.

What a good formula prompt contains

A complete request answers four questions. Leave one out and the assistant fills it in with a guess, which is where the trouble starts.

QuestionWhat to sayWhat happens if you skip it
Where is the data?Sheet names and ranges, or the header namesIt invents column letters that don't match yours
What identifies a row?The key column, and whether keys repeatYou get the first duplicate, silently
What comes out?A number, a label, a date, a spilled rangeYou get text where you needed something to sum
What about the awkward rows?Blanks, no match, zero, negativesErrors turn up later, usually in front of someone
A complete request
Sheet `Sales` has headers in row 1: A=Date, B=Rep, C=Region, D=Amount, rows 2:8000. Give me a formula for total Amount for the rep named in G2, only for dates in the current quarter. Treat blank Amounts as zero. Google Sheets.

Describe the result, not the function

Most people prompt with the function they half-remember. "Write me a SUMIF." But naming the function constrains the answer, and it's often the wrong constraint. SUMIF can't take two criteria. VLOOKUP can't look left. You've narrowed the search before anyone knew what you needed.

Say what you want instead. "Total revenue for this region in this month." Let the assistant pick the function. If you do have a reason to prefer one, because a colleague has to maintain it or the file opens in an old version, say that as a constraint rather than as the request.

Check it in sixty seconds

A formula that produces a number is not the same as a formula that produces the right number. Three checks catch nearly everything.

1

Test a row you can do in your head

Pick a case with an obvious answer. If the formula and your mental arithmetic disagree, you've found the bug in ten seconds rather than at quarter end.

2

Break it deliberately

Feed it a blank, a duplicate key, a value with no match, a zero. All of those exist somewhere in your real data. Watch what comes back.

3

Check the range reaches the bottom

A range ending at row 500 in a sheet with 900 rows is the classic silent error. Use whole-column or table references where you can.

Where AI-written formulas go wrong

Spill behaviour

Dynamic arrays cause most of the "it works in one cell but not when I drag it" complaints. You may get a spilling formula when you wanted one value per row, or the reverse. Say which you want. "One formula in the top cell that spills down" or "a formula I can fill down each row" is enough.

Numbers that are secretly text

If the column came from a CSV, the dates may be text and the numbers may be carrying invisible non-breaking spaces. The formula is fine, the data isn't. When a SUMIFS returns zero for criteria you can see in the sheet, this is almost always why. Check =ISNUMBER(D2) before you rewrite anything, and see the cleaning checklist for the repair.

Links to other files

External references break in ways that are painful to debug and worse to inherit. If an assistant suggests one, ask whether the data could be imported into a tab instead. A stale link that still returns cached values is one of the nastier things that can happen to a workbook.

Volatile functions in big sheets

OFFSET, INDIRECT, NOW and friends recalculate on every change. Scatter them through 20,000 rows and you get a workbook that hangs for eight seconds after every keystroke. Ask for a non-volatile version. INDEX usually replaces OFFSET without any fuss.

Prompt patterns worth stealing

Lookup with a fallback
Return the price from Products!A:D (A=SKU, D=Price) for the SKU in B2. If the SKU isn't there, return "Not listed" rather than an error.
Conditional total with a date window
Count rows in Tickets!A2:E9000 where E="Open" and the date in A falls in the last 30 days.
Cleaning inside the formula
Compare Emails!B and Signups!C, matching case-insensitively and ignoring leading and trailing spaces on both sides.
Understanding what you inherited
Explain this formula step by step, then tell me which parts break if someone inserts a column at C.

Converting formulas between Excel and Sheets

This is one of the more reliable AI jobs, because the mapping is mechanical rather than creative. Array behaviour, ARRAYFORMULA wrapping, QUERY versus filtering, and the handful of functions with different names. Say which direction you're going and test on a sample before you migrate anything that matters. The formula converter does this in both directions.

When the assistant can see the sheet

Everything above is really about compensating for an assistant that's working blind. Once the tool has your workbook, with real headers, real value types and real row counts, most of that detail stops being necessary. "Total revenue by region for Q3" is enough, because nothing about your structure is a guess anymore.

The error modes change too, which is the part worth knowing. A blind assistant makes plausible mistakes about your structure. One that can read the sheet makes far fewer of them, and it can tell you when your request doesn't match the data at all, which is often the most useful answer available.

Generate a formula against your real columns

SheetAI reads your workbook, writes the formula into the cell, and explains each argument, so you can check it rather than trust it.

Write a formula in SheetAI

Frequently asked questions

What is an AI formula generator?

›
A tool that turns a plain-English description into a working spreadsheet formula. The better ones read your actual sheet, so they use your real column names and data types instead of asking you to describe them or guessing.

Why does my AI-generated formula return #REF! or #VALUE!?

›
#REF! usually means it points at a range or sheet name that doesn't exist, normally because the assistant guessed at your structure. #VALUE! is usually a type mismatch, most often numbers or dates stored as text after a CSV import. Check with ISNUMBER() before rewriting the formula.

Can AI convert Excel formulas to Google Sheets?

›
Yes, and it's one of the more dependable conversions because the differences are mechanical: array behaviour, ARRAYFORMULA wrapping, QUERY versus filtering, and a few renamed functions. State the direction and test on a sample before migrating a whole workbook.

Should I ask for a formula or let AI edit the sheet directly?

›
Ask for a formula when the source data will keep changing, since a formula recalculates and pasted values don't. Let it write values for one-off jobs like tagging or parsing, where re-running means nothing. Either way, put the result in a new column.

Is there a free AI formula generator?

›
Ours is free to try without a subscription, and there are others. The thing to compare isn't price but whether the tool can see your data. A generator that only reads your prompt will always be guessing at your column names.

Written by The SheetAI Team

We build SheetAI, an AI spreadsheet assistant that reads your data, writes the formulas, and shows its work. We write about the spreadsheet problems we keep running into.

Get started

Put this to work on your own spreadsheet

Upload a file, ask in plain English, and watch SheetAI write the formulas into the sheet, with every step visible so you can check the work.

All articles

Works in your browser and Google Sheets · Setup in 30 seconds