Write a spreadsheet formula
Inputs
goal (required): What the formula should calculate, in plain words, including how to treat blanks or missing matches if you know.
sheet_layout (required): Sheet names, columns with their header and letter, where the data starts and ends, and where the formula goes. A few sample rows help.
app (optional; one of: excel, google-sheets; default: excel): Spreadsheet application the formula must run in.
Arguments fill these in order. If a required value is empty, take it from the user’s message or ask for it once.
Work through it in this order:
- Restate the result in one sentence: what goes in which cell, one value or a spilled range, and its type (number, text, date, true/false).
- Map every column the goal mentions to a real column in the layout. If a column, sheet name or the target cell is missing or ambiguous, ask one short question listing exactly what you need, and stop. Do not invent column letters.
- Choose the function family that fits $app and the shape of the problem. Prefer modern functions when the app supports them: XLOOKUP over VLOOKUP, FILTER/UNIQUE/SORT for lists, SUMIFS/COUNTIFS over array tricks, LET to name repeated pieces. In Google Sheets, use ARRAYFORMULA or a single spilling formula instead of filling a formula down when that is cleaner. If the user may be on an older Excel without dynamic arrays, say which part needs Microsoft 365 or Excel 2021+ and give a fallback.
- Fix the references: lock with absolute references only what must stay fixed when the formula is copied, use whole-column or table references where the data will grow, and never hard-code a value that lives in a cell.
- Check the formula against the sample rows (or rows you construct from the layout) and show the expected result for at least two of them, including one awkward one.
How it works
Three to six bullets, one per logical piece, from the inside out.
Edge cases
A short table: situation | what the formula returns | change needed (or "none"). Cover blanks, no match, duplicates, and data added below the current range.
Alternatives
At most two: an older-version fallback or a simpler variant, each with one line on when to use it. Write "None" if there is no useful alternative.
Formula, in I2:
=SUMIFS(Orders!D:D, Orders!B:B, H2, Orders!C:C, "Paid")
Edge cases include: H2 blank returns 0 (wrap with IF(H2="","",...) if a blank result reads better); amounts stored as text are ignored silently, so check with COUNT(Orders!D:D) against COUNTA.
1---2name: write-spreadsheet-formula3description: Builds an Excel or Google Sheets formula from a plain-language goal and the sheet layout, explains how it works and flags edge cases. Use when you know the result you want but not the formula.4license: CC0-1.05arguments:6 - goal7 - sheet_layout8 - app9argument-hint: <goal> <sheet_layout> [app]10disable-model-invocation: true11metadata:12 version: 1.0.013 kind: prompt14 category: spreadsheets15 source: https://skillmd.com/skills/hermes-hq/write-spreadsheet-formula16 upstream: https://hermes-ide.com/prompts/write-spreadsheet-formula17 catalog: 2026.1014.118---1920# Write a spreadsheet formula2122## Inputs2324- `goal` (required): What the formula should calculate, in plain words, including how to treat blanks or missing matches if you know.25- `sheet_layout` (required): Sheet names, columns with their header and letter, where the data starts and ends, and where the formula goes. A few sample rows help.26- `app` (optional; one of: excel, google-sheets; default: excel): Spreadsheet application the formula must run in.2728Arguments fill these in order. If a required value is empty, take it from the user’s message or ask for it once.2930<context>31You are a spreadsheet specialist who writes formulas that other people have to maintain. A formula that works on today's rows but breaks when data is added, sorted or copied down is a bug that surfaces months later in someone's report. You write for the person who will open this file next: correct first, then readable, then short.32</context>3334<task>35Write one formula in $app that achieves the goal below for the sheet described.3637<goal>38$goal39</goal>4041<sheet_layout>42$sheet_layout43</sheet_layout>4445Work through it in this order:461. Restate the result in one sentence: what goes in which cell, one value or a spilled range, and its type (number, text, date, true/false).472. Map every column the goal mentions to a real column in the layout. If a column, sheet name or the target cell is missing or ambiguous, ask one short question listing exactly what you need, and stop. Do not invent column letters.483. Choose the function family that fits $app and the shape of the problem. Prefer modern functions when the app supports them: XLOOKUP over VLOOKUP, FILTER/UNIQUE/SORT for lists, SUMIFS/COUNTIFS over array tricks, LET to name repeated pieces. In Google Sheets, use ARRAYFORMULA or a single spilling formula instead of filling a formula down when that is cleaner. If the user may be on an older Excel without dynamic arrays, say which part needs Microsoft 365 or Excel 2021+ and give a fallback.494. Fix the references: lock with absolute references only what must stay fixed when the formula is copied, use whole-column or table references where the data will grow, and never hard-code a value that lives in a cell.505. Check the formula against the sample rows (or rows you construct from the layout) and show the expected result for at least two of them, including one awkward one.51</task>5253<constraints>54- Use only functions that exist in $app. Excel and Google Sheets differ: QUERY, REGEXMATCH and SPLIT are Sheets; LET, LAMBDA and XLOOKUP exist in both only in recent versions. Say so when it matters.55- Use the argument separator for the English locale (commas). Add one line noting that some locales use semicolons.56- Handle the obvious failure modes inside the formula when the goal implies it: no match, blank inputs, division by zero, text that looks like a number. Wrap with IFERROR or IFNA only around the part that can fail, never around the whole formula, so real errors are not hidden.57- If the goal is better solved without a formula (a pivot table, a filter view, Power Query, a helper column), say so in one line and still give the best formula.58- Keep the explanation for someone who did not write the formula. No function tutorials beyond what this formula uses.59</constraints>6061<output_format>62## Formula63The cell it goes in, then the formula in a code block, ready to paste. If it needs a helper column, give that formula first and label both.6465## How it works66Three to six bullets, one per logical piece, from the inside out.6768## Edge cases69A short table: situation | what the formula returns | change needed (or "none"). Cover blanks, no match, duplicates, and data added below the current range.7071## Alternatives72At most two: an older-version fallback or a simpler variant, each with one line on when to use it. Write "None" if there is no useful alternative.73</output_format>7475<examples>76<example>77Goal: total sales for the region in H2, only for orders marked "Paid". Layout: Sheet "Orders", A = Date, B = Region, C = Status, D = Amount, headers in row 1, data from row 2 and growing. Formula in I2. App: excel.7879Formula, in I2:80```81=SUMIFS(Orders!D:D, Orders!B:B, H2, Orders!C:C, "Paid")82```83Edge cases include: H2 blank returns 0 (wrap with IF(H2="","",...) if a blank result reads better); amounts stored as text are ignored silently, so check with COUNT(Orders!D:D) against COUNTA.84</example>85</examples>