AI for Excel: Write Formulas and Clean Tables with a 5-Step Prompt

Blog / AI concepts

AI for Excel: Write Formulas and Clean Tables with a 5-Step Prompt

Using AI to write Excel formulas is simple: give it your column headers, a few rows of sample data, and the result you want. Ask it to produce the formula and explain each part, then check the formula against a few rows where you already know the answer. The main risk with AI and Excel is not that it can't write a formula. It's that the formula looks right and quietly returns wrong results, so don't skip the verification step. Also, don't upload an entire spreadsheet that contains personal information or trade secrets.

What can AI do for Excel?

These are the tasks that suit AI well:

  • Writing formulas: conditional sums, multi-criteria lookups, splitting and joining text, date calculations.
  • Explaining formulas: translating a long nested formula a coworker left behind into plain language.
  • Cleaning data: trimming spaces, standardizing date formats, splitting an address into province/city/district, rules for deduplication.
  • Designing pivot tables: telling you which field goes in rows, columns, values, and filters.
  • Troubleshooting errors: paste the formula and the error message and let it analyze the cause.

What doesn't suit it: asking it to "take a look" at a big table and report numbers. Large language models are error-prone at precise calculation over large batches. A more reliable approach is to have it write the formula and let Excel do the math.

How do you describe a sheet so AI gets it right?

AI can't see your spreadsheet, so a wrong formula is usually the result of missing information. Use the five steps below as a template.

  1. State the software and version: Excel 365, Excel 2016, WPS, or Google Sheets. Some functions don't exist in older versions; check your software's official documentation for that.
  2. List the headers and column positions, for example "Column A is the date, column B is the salesperson, column C is the amount, and the data runs from row 2 to row 500."
  3. Give 3 to 5 sample rows, using made-up data.
  4. Say what result you want and where it goes, for example "In cell F2, total the amounts for salesperson Alice in March."
  5. Ask it to explain the formula and to name the situations where it might fail, such as blanks, numbers stored as text, or duplicates.

Example prompt:

I'm using Excel 365. Column A is the date (e.g. 2026-03-05), column B is the salesperson, column C is the amount, and the data is in rows 2 to 500.
Please write a formula that, in F2, totals column C where column B matches the content of cell F1 and the date falls in March 2026.
Explain the formula step by step, and tell me what happens if the dates are stored as text.

How do you phrase common tasks?

TaskWhat to add to your prompt
Conditional sum / countThe condition column, the condition value, and whether there are multiple conditions
Lookup and matchWhich column holds the lookup value, which column to return, and what to show if nothing is found
Text splittingWhat the delimiter is and whether any rows are irregular
Date calculationsWhether the dates are real dates or text, and whether to exclude weekends
Data cleaningPaste a few dirty rows and describe what the clean version should look like
Pivot tablesThe business question you want answered, not just "make a pivot table"

For pivot tables, start with the business question, for example "total amount per salesperson per month," and then ask the AI which field belongs in which area. Menu locations vary by version, so check the official documentation.

How do you verify a formula once you have it?

This is the most important part. Work through this checklist:

  • Pick 3 to 5 rows, calculate them by hand, and compare with the formula's results.
  • Try a condition that should match nothing or sum to zero, and see whether the formula errors out or returns something odd.
  • Check whether numbers are stored as text. Left-aligned numbers and a small green triangle in the corner of the cell are common clues.
  • Compare two methods: for example, summarize once with a pivot table and once with a formula. The totals should match.
  • Check that the formula's range covers all the data, and that references didn't shift when you filled down.
  • Ask the AI to write it a different way. If the two formulas give different results, you need to dig further.

If the formula throws an error, paste the formula text and the error message back in, and it can usually find the problem. You still need to verify it yourself. Don't accept a fix just because the AI says "fixed."

What if the sheet contains sensitive data?

Don't upload whole customer lists, national ID numbers, payroll sheets, or contract amounts. What you can do instead:

  • Give only the headers and a few made-up sample rows. That's enough for AI to write a formula.
  • Replace names, phone numbers, and the like with placeholders such as "Customer A" or "138xxxx" before asking.
  • If your company has a policy, follow it first. For the actual data-handling terms, rely on the official terms of the service you use. For the company-level considerations, see What to consider when your company buys AI tools: compliance, data, and accounting.

Once the formula is written, run it in your own copy of Excel. The full data never needs to go to the AI. That is another reason "have AI write the formula" is safer than "have AI process the spreadsheet directly."

Which way of accessing AI fits best?

If you only write a few formulas now and then, the web version or an app is enough. See How to get started with AI as a beginner: web, app, or API first. If your questions aren't coming out well, the structure in How to write prompts: a four-element template beginners can copy can be borrowed directly. For more office scenarios (email, meeting notes, and so on), see AI for office work: how to hand off email, spreadsheets, slides, and meeting notes.

As you use AI more, you'll run into the question of subscription versus API. See Subscription or API for beginners: choose by use case. When you run out of quota, see What to do when your AI plan's quota runs out: wait for reset, buy more, or switch.

If you want access to several models under one subscription, you can look at AGI Plan. It is a multi-provider LLM aggregation gateway with monthly subscriptions, billed in Chinese yuan (RMB), with no overseas credit card needed; tools like Claude Code and Codex only need a single endpoint address changed. Some models are marked "overseas only," so rely on AGI Plan's model page for specifics. It is also not an officially authorized channel. AGI Plan is a commercial partner of cdnping. If all you need is formulas, you usually won't need any of this, and the web version is enough. If you're interested, see the setup guide.

If the web version won't load or feels slow, check the service status on cdnping's "Is it down?" page to decide whether the problem is on your network or on the service side.

What should you do next?

Pick one small real task you have on hand, such as "total a column by month." Write the prompt using the five steps above, and when you get the formula, run it through the verification checklist. Once you're sure it's right, extend it to the whole sheet. When the routine feels natural, move on to more complex tasks like data cleaning and pivot tables.

Related articles

Keep reading