# write_sheet_formula (https://sellersheetai.com/docs/mcp-api/tools/write_sheet_formula)

> Fill one formula into a cell — or across EVERY cell of a range.

Access: **DESTRUCTIVE** · toolset google_workspace · family null

## Call it

MCP tool call:

```json
{
  "name": "write_sheet_formula",
  "arguments": {
    "spreadsheet_id": "<spreadsheet_id>",
    "range_": "<range_>",
    "formula": "<formula>"
  }
}
```

Tool API (early access — contact us):

```bash
curl -X POST https://api.sellersheetai.com/api/v1/tools/write_sheet_formula \
  -H "Authorization: Bearer $SELLERSHEET_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"spreadsheet_id":"<spreadsheet_id>","range_":"<range_>","formula":"<formula>"}'
```

## Arguments

| Name | Type | Required | Description |
|---|---|---|---|
| `spreadsheet_id` | string | yes | the spreadsheet ID (from its URL or get_sheet_metadata). |
| `range_` | string | yes | a single cell ('Sheet1!A1'), or a block that names its tab and both row ends ('Sheet1!A2:A45'). 'A2:A45' and 'A2:A' are refused. |
| `formula` | string \| object[] | yes | Formula string starting with '='. Also accepts a 2D list of formula strings (one per cell) — in that mode it behaves exactly like write_sheet (no fan-out; each cell gets its own literal formula), kept for compatibility. |

## Result

- `data.cellCount` — the cells filled.
- `data.multiCell` — true when one formula was fanned out across the range (string mode only).

## Gotchas

- Pass a bare formula string and the target range:
- Single cell ('Sheet1!A1')  → written via values.update (USER_ENTERED).
- Multi-cell range ('_raw_ppc!J2:J45') → the SAME formula is filled into every cell via one batchUpdate.repeatCell call, and Google increments the relative references per cell (so '=B2*C2' in row 2 becomes '=B3*C3' in row 3, and so on). The success message reports the real filled extent, e.g. "Formula filled across _raw_ppc!J2:J45 (44 cells, relative references adjusted per cell)". Use write_sheet directly when:
- Mixing values and formulas in the same block
- Each cell needs a DIFFERENT formula (pass an explicit 2D list)
- You want explicit 2D shape control This is a real fan-out: unlike write_sheet with a 1-row 2D list, it does NOT leave J3:J45 empty. Every range here must name its tab and both ends ('Tab!A1:D10'); a range without a tab ('A1:D10') or with an open end ('Tab!A:D') is refused. A single cell is exempt.

## Example

- write_sheet_formula("1ABC", "Sheet1!A1", "=SUM(B:B)") write_sheet_formula("1ABC", "Inventory!Q9", "=SPARKLINE(_raw_woc!C2:P2)") # Same formula fanned across a bounded range — relative refs adjust per row: write_sheet_formula("1ABC", "_raw_ppc!J2:J45", "=IF(G2>0,F2/G2,\"\")")