Using AI to Write Excel Formulas

How AI Understands Excel Formula Requests

Modern AI tools like ChatGPT, Claude, and GitHub Copilot can generate accurate Excel formulas when you describe your data layout and the desired outcome clearly. The key is providing context: column letters, data ranges, and what result you expect. For example, instead of saying "give me a lookup formula," say "I have employee IDs in column A of Sheet1 and names in column A of Sheet2 with salaries in column B. I need to pull each employee's salary into column C of Sheet1." The more specific your prompt, the higher the chance of getting a correct formula on the first try.

AI models have been trained on millions of Excel formula examples from documentation, forums, and tutorials. They understand the syntax of hundreds of functions and can combine them into nested formulas that would take a human several minutes to construct and debug. However, they rely on you to provide the structural context — row numbers, sheet names, and data types — since they cannot see your actual spreadsheet.

Essential Formula Categories AI Excels At

AI tools perform exceptionally well across these formula categories:

Real-World Formula Examples with AI Prompts

Example 1: Two-Way Lookup with INDEX-MATCH-MATCH

Prompt: "I have a sales table where rows (A3:A12) are product names and columns (B2:E2) are quarters (Q1-Q4). I need a formula that looks up sales for a specific product (entered in cell G1) and a specific quarter (entered in H1). Give me INDEX-MATCH-MATCH."

AI-generated formula:

=INDEX(B3:E12, MATCH(G1, A3:A12, 0), MATCH(H1, B2:E2, 0))

This formula uses the first MATCH to find the row position of the product in G1 within A3:A12, the second MATCH to find the column position of the quarter in H1 within B2:E2, and INDEX to return the value at that intersection.

Example 2: Multi-Condition SUMIFS with Date Range

Prompt: "Column A has dates, Column B has product categories, Column C has sales amounts. I need to sum sales for the 'Electronics' category between January 1, 2026 and March 31, 2026. The data runs from row 2 to row 500."

AI-generated formula:

=SUMIFS(C2:C500, B2:B500, "Electronics", A2:A500, ">=1/1/2026", A2:A500, "<=3/31/2026")

The SUMIFS function evaluates three conditions simultaneously: category must match "Electronics," and the date must fall within the Q1 2026 range. Each condition pair follows the pattern (criteria_range, criteria).

Example 3: Nested IF with Percentage Tiers

Prompt: "Column D has sales figures. I need to assign a commission tier: 0-5000 gets 5%, 5001-10000 gets 7%, 10001-20000 gets 10%, above 20000 gets 12%. Write it as a formula for row 2."

AI-generated formula:

=IF(D2<=5000, D2*0.05, IF(D2<=10000, D2*0.07, IF(D2<=20000, D2*0.10, D2*0.12)))

For Excel 2019 and newer, AI may suggest the cleaner IFS alternative:

=IFS(D2<=5000, D2*0.05, D2<=10000, D2*0.07, D2<=20000, D2*0.10, TRUE, D2*0.12)

Example 4: FILTER with Multiple Criteria (Dynamic Array)

Prompt: "My data is in A2:D200 with headers: Name, Department, Salary, Location. I need to filter and show all rows where Department is 'Engineering' AND Salary is greater than 80000. Use the FILTER function."

AI-generated formula:

=FILTER(A2:D200, (B2:B200="Engineering")*(C2:C200>80000), "No matching records")

The multiplication acts as a logical AND operator within the FILTER function — each TRUE evaluates to 1, and only rows where both conditions are TRUE (1*1=1) pass through the filter.

Prompt Engineering for Excel Formulas

Getting reliable formulas from AI requires structured prompts. Here is a proven template:

Prompt Template:
"I'm using [Excel version, e.g., Excel 365]. My data is structured as follows:
- [Column A header]: [description, data type, sample value]
- [Column B header]: [description, data type, sample value]
I need a formula that [specific outcome]. The formula should go in [target cell/column]. Additional constraints: [handle blanks, case sensitivity, etc.]"

Key techniques that improve AI formula accuracy:

  1. Specify your Excel version: Excel 365 supports dynamic arrays (FILTER, SORT, UNIQUE) and LAMBDA; older versions need traditional array formulas with Ctrl+Shift+Enter.
  2. Provide exact cell ranges: Replace "my sales data" with "A2:A500 named SalesData."
  3. Mention edge cases: Tell the AI how to handle blank cells, errors, duplicates, or zero values.
  4. Request alternatives: Ask "give me two approaches" to compare VLOOKUP vs INDEX-MATCH or SUMIFS vs SUMPRODUCT.
  5. Ask for explanation: Adding "explain how this formula works step by step" helps you learn and verify correctness.

Common Pitfalls and How to Validate AI-Generated Formulas

AI-generated formulas are not infallible. Watch for these recurring issues:

Validation checklist:

  1. Copy the formula into your spreadsheet and test on 3-5 known values.
  2. Check edge cases: blank cells, maximum/minimum values, text in numeric columns.
  3. Use Formula Auditing (Formulas tab > Evaluate Formula) to step through the calculation.
  4. Compare against a manual calculation for at least one row.
  5. If the formula returns an error, ask the AI: "This formula returned #N/A. My data range is A2:B50. What could be wrong?"

Building a Personal AI Formula Library

As you accumulate AI-generated formulas that work for your specific datasets, organize them into a reusable library. Create an Excel workbook with separate sheets for each formula category: Lookup, Text, Date, Conditional, Financial. On each sheet, include columns for the original prompt, the generated formula, a plain-English description of what it does, and notes on any modifications you made after testing.

For team environments, use Excel's LAMBDA function (Excel 365) to package complex AI-generated formulas into named, reusable custom functions. For example, a LAMBDA wrapping the INDEX-MATCH-MATCH logic above can be defined once and called from any cell in any workbook:

=LAMBDA(lookup_val, row_header, col_header, data_range, row_range, col_range, INDEX(data_range, MATCH(lookup_val, row_range, 0), MATCH(col_header, col_range, 0)))

Assign this LAMBDA to a name like "TwoWayLookup" in Name Manager, and your entire team can use =TwoWayLookup(G1, H1, B3:E12, A3:A12, B2:E2) without understanding the underlying INDEX-MATCH mechanics.

When AI Falls Short and What to Do

AI struggles with formulas that depend on visual layout cues it cannot perceive — merged cells, hidden rows, conditional formatting rules, or data validation constraints. It also cannot reference external workbooks or handle volatile real-time data (stock prices, API feeds). In these cases:

Have questions or found an error in this article?