Using ChatGPT, Claude or Gemini for Excel and Google Sheets Formulas
ChatGPT, Claude and Gemini can all write spreadsheet formulas from a plain-English description. They know the syntax of common Excel and Google Sheets functions well, and they are good at explaining a formula someone else wrote.
What they cannot know is how your sheet is laid out. Most wrong AI formulas are correct formulas pointed at the wrong columns, or written for a function your version does not have. This guide shows the prompt pattern that avoids that, eight formulas we tested on a sample sheet, and a quick way to check any formula before you rely on it.
The prompt pattern
I use [Excel 365 / Excel 2019 / Google Sheets].
Sheet "Orders", headers in row 1, data in rows 2 to [LAST ROW]:
A = Invoice, B = Date, C = Region, D = Rep, E = Amount, F = Status (Paid/Unpaid)
In [CELL] I want [RESULT].
Edge cases: [blank rows / no match / text in number column].
Give one formula, then explain each argument in one line.
The app and version line matters most: Microsoft’s documentation says XLOOKUP is not available in Excel 2016 and Excel 2019 (Microsoft), so a formula that works in Excel 365 may fail for a colleague. You do not need to paste real data. Headers and a few made-up rows are enough, which also keeps customer details out of the chat. More templates like this are in our office prompt templates.
The sample data
Every formula below was entered into this sheet and recalculated (in LibreOffice 25.2, which supports the same functions). The results shown are what the sheet returned, and we checked each one by hand.
| A Invoice | B Date | C Region | D Rep | E Amount | F Status | |
|---|---|---|---|---|---|---|
| 2 | INV-1001 | 2026-09-28 | North | ” ana LOPEZ ” | 1200 | Paid |
| 3 | INV-1002 | 2026-10-02 | South | Ben Okafor | 850 | Unpaid |
| 4 | INV-1003 | 2026-10-05 | North | Ana Lopez | 430 | Paid |
| 5 | INV-1004 | 2026-10-09 | East | chris wu | 2100 | Unpaid |
| 6 | INV-1005 | 2026-10-14 | North | Ben Okafor | 640 | Unpaid |
| 7 | INV-1006 | 2026-10-20 | South | Chris Wu | 975 | Paid |
| 8 | INV-1007 | 2026-10-27 | North | Ana Lopez | 310 | Paid |
| 9 | INV-1008 | 2026-11-01 | East | Ben Okafor | 1500 | Unpaid |
Eight formulas, explained and verified
1. Total with two conditions: paid sales in the North
=SUMIFS(E2:E9,C2:C9,"North",F2:F9,"Paid")
SUMIFS takes the range to add first, then pairs of (range, condition). Here it adds Amount where Region is “North” and Status is “Paid”. Result: 1940 (1200 + 430 + 310). Argument order is the same in Excel and Google Sheets. The older SUMIF puts the sum range last, a frequent source of AI mix-ups.
2. Look up an invoice amount, with a fallback
=XLOOKUP("INV-1004",A2:A9,E2:E9,"Not found")
Search for the invoice in column A and return the matching value from column E. The fourth argument is what to show if there is no match; without it you get #N/A. Result: 2100. With “INV-9999” instead, the result is “Not found”. Microsoft calls the fourth argument if_not_found and Google calls it missing_value (Google); the position is the same. For Excel 2019 or earlier, ask for an INDEX/MATCH version instead.
3. Count invoices in a month
=COUNTIFS(B2:B9,">="&DATE(2026,10,1),B2:B9,"<="&DATE(2026,10,31))
Two conditions on the same date column: on or after 1 October and on or before 31 October. The & joins the comparison sign to the date. Result: 6 (rows 3 to 8). If this returns 0 on your sheet, your dates are probably stored as text; check by changing a date cell’s format to Number.
4. Total for a date range
=SUMIFS(E2:E9,B2:B9,">="&DATE(2026,10,1),B2:B9,"<"&DATE(2026,11,1))
Same idea, adding amounts. Using “before 1 November” instead of “on or before 31 October” also catches times late on the 31st if your dates include times. Result: 5305 (850 + 430 + 2100 + 640 + 975 + 310).
5. Flag overdue invoices
=IF(AND(F3<>"Paid",DATE(2026,11,15)-B3>30),"Overdue","")
If the invoice is not paid and more than 30 days have passed, show “Overdue”; otherwise leave the cell blank. Subtracting dates gives days. Result for row 3 checked on 15 November: “Overdue” (44 days). Checked on 1 November it is blank, because 30 days is not more than 30. In real use, replace DATE(2026,11,15) with TODAY() and fill the formula down.
6. Clean up messy names
=PROPER(TRIM(D2))
TRIM removes extra spaces; PROPER capitalises each word. Result: “Ana Lopez” from ” ana LOPEZ ”. This makes names match for counting and lookups. PROPER will get names like “McDonald” wrong (“Mcdonald”), so scan the results.
7. Average for one region
=ROUND(AVERAGEIFS(E2:E9,C2:C9,"North"),2)
Average Amount where Region is North, rounded to two decimals. Result: 645 ((1200 + 430 + 640 + 310) ÷ 4).
8. Working days between two dates
=NETWORKDAYS(DATE(2026,11,2),DATE(2026,11,13))
Counts Monday-to-Friday days between two dates, including both ends. 2 November 2026 is a Monday and 13 November a Friday. Result: 10. An optional third argument takes a range of holiday dates to exclude (Microsoft).
How to check any AI formula
- Pick two rows where you know the answer. Work them out by hand or with a filter, and compare.
- Test a “no result” case. A region that does not exist should return 0 or your fallback text, not an error.
- Test an edge case. A blank row, a date at the boundary, a name with extra spaces.
- Ask for the explanation, then read it against your columns. If the AI says “column C is Amount” and it is not, the formula is wrong even if it returns a number.
- Check after filling down. Ask whether ranges should be fixed with
$(for example$E$2:$E$9) so they do not shift when copied.
Excel or Sheets differences worth telling the AI
- Version. XLOOKUP needs Excel 2021 or later, Excel for Microsoft 365, or Google Sheets.
- Separators. In some regional settings, arguments are separated with semicolons rather than commas. If a pasted formula is rejected, that is the first thing to check.
- Sheets-only functions. Google Sheets has functions such as QUERY that Excel does not. If colleagues use Excel, ask for a formula that works in both.
Should you paste the spreadsheet itself?
Usually not. Headers and invented sample rows are enough for formula help. If you want the AI to analyse real figures, check what your plan does with uploaded files first: see Is it safe to put company data into ChatGPT, Claude or Gemini?.
If formula help saves you time every week, estimate what that is worth, after subtracting checking time, with the worked example in how much time AI really saves a small business.
Frequently asked questions
Can ChatGPT write Excel formulas?
Yes, and so can Claude and Gemini. They are reliable on syntax for common functions like SUMIFS and XLOOKUP. They make mistakes when they have to guess your column layout, so always describe the columns and test the result.
Do Excel and Google Sheets formulas work the same way?
Most common functions have the same name and argument order in both. Some differ in availability. Microsoft says XLOOKUP is not available in Excel 2016 and Excel 2019, so tell the AI which app and version you use.
How do I know if an AI formula is correct?
Test it on rows where you already know the answer. Pick two or three cases, work them out by hand or with a filter, and compare. Then test an edge case such as a blank cell or a value that does not exist.
Is it safe to paste my spreadsheet into an AI chat?
Often you do not need to. Column names and two or three made-up rows are enough for the AI to write a formula. Avoid pasting customer, payroll or financial data unless your plan and company policy allow it.
Why does the AI's formula return an error?
Common causes are a different column layout than you described, dates stored as text, a function your version does not support, or a regional setting that uses semicolons instead of commas between arguments.
Related tutorials
Sources
- XLOOKUP function — Microsoft
- XLOOKUP function (Google Sheets) — Google
- SUMIFS function — Microsoft
- SUMIFS function (Google Sheets) — Google
- COUNTIFS function — Microsoft
- NETWORKDAYS function — Microsoft