TRIMRANGE
Short answer
Ranges that grow with the data, no OFFSET
TRIMRANGE(range, [trim_rows], [trim_cols])
- Category
- Dynamic Arrays & Modern Excel
- Excel version
- 365
- Also searched as
- trim references, dynamic range without offset, dot colon excel, a:.a reference, range that grows with data, trim empty rows from range
What it returns
TRIMRANGE takes a range and removes the empty rows and columns from its outer edges. TRIMRANGE(Bank!A2:F20000) on a tab where the bank feed fills rows 2 to 1,437 returns A2:F1437. Paste next month’s feed, longer or shorter, and the result follows it.
Trim references are the shorthand for the same thing, and the form you will use most. A dot beside the colon tells Excel which end to trim:
| Reference | Trims |
|---|---|
A2:.F20000 | Trailing empty rows and columns (the end) |
A2.:F20000 | Leading empty rows and columns (the start) |
A2.:.F20000 | Both ends |
A:.F | Whole columns, trimmed to the used rows |
Only the edges are trimmed. A blank row in the middle of the data stays, because something sits below it.
Arguments that matter
| Argument | Required | What it does |
|---|---|---|
range | Yes | The range to trim. Size it generously: Bank!A2:F20000. |
trim_rows | No | 0 none, 1 leading, 2 trailing, 3 both (default). |
trim_cols | No | Same codes for columns. Default 3, both. |
The defaults trim everything, which is what you want almost every time. The function form earns its place when you need different treatment for rows and columns. TRIMRANGE(Bank!A2:F20000, 2, 0) trims empty rows from the bottom but always keeps all six columns, even if column F is empty this month.
A trim reference trims rows and columns together and cannot split them. When a column might be empty and you still need it in the output, use the function.
In a financial model
Two habits have filled models with slow or fragile ranges. The first is the whole-column reference, Bank!F:F. In SUM or SUMIFS it is cheap, but inside an array calculation, such as a FILTER or a multiplication by an FX rate, Excel works through all million rows. The second is the OFFSET dynamic range, OFFSET(A2, 0, 0, COUNTA(A:A)-1, 6), which the play on avoiding volatile functions flags because it recalculates on every edit anywhere in the workbook.
Trim references replace both. Bank!A:.F reads like a whole column but stops at the last used row. It is not volatile and it does not count rows with COUNTA, so a blank cell in column A no longer cuts the range short.
The use is raw data that arrives as a paste or a query output rather than an Excel Table. The play on raw data staying raw keeps that data untouched on its own tab. A Table is still the better container when you control the tab. When you do not, because a system export lands in fixed columns, a trim reference is how the model reads it safely.
Trim the block once, not each column. A single trimmed block has one height. Columns trimmed separately can end at different rows, and functions that need equal sizes fail.
Worked example
A tab Bank receives the monthly bank feed as a paste into A2:F, headers in row 1. Columns are Date, Ref, Payee, Category, Currency, Amount. The paste runs anywhere from 900 to 2,000 rows.
Spend by category, read from the trimmed block:
=LET(
feed, Bank!A2:.F20000,
GROUPBY(CHOOSECOLS(feed, 4), CHOOSECOLS(feed, 6), SUM))
feed is the trimmed block, one height for every column. CHOOSECOLS picks the category and amount columns from it, and GROUPBY summarizes.
| Range | Rows returned |
|---|---|
Bank!A2:F20000 | 19,999, mostly empty |
Bank!A2:.F20000 | 1,436 this month |
Bank!A:.F | 1,437 (includes the header) |
The whole-column form keeps row 1. Strip it with DROP(Bank!A:.F, 1) if you prefer no upper bound.
The completeness check, comparing the trimmed block to the raw column:
=SUM(CHOOSECOLS(Bank!A2:.F20000, 6)) - SUM(Bank!F:F)
Expected zero. Anything else means data sits below row 20,000, beyond the trim reference’s bound.
Old way vs new way
The legacy dynamic range was a named OFFSET counting the rows in column A:
=OFFSET(Bank!$A$2, 0, 0, COUNTA(Bank!$A:$A)-1, 6)
The new version:
=Bank!A2:.F20000
OFFSET is volatile and depends on column A having no blanks. A single empty date cell made COUNTA one short and dropped the last transaction. The trim reference reads the extent of the data itself and recalculates only when the tab changes.
Where it breaks
The totals stop growing after a big month. The data passed the reference’s end bound, A2:.F20000, and rows below 20,000 are ignored. Fix: set the bound well above any realistic paste, or use whole columns, A:.F, and DROP the header row. Keep the completeness check above in the check row.
Zeros appear in the middle of the result. The paste has blank rows inside it. Trimming only removes empty rows at the edges, so interior blanks come through as zeros. Fix: filter them out, FILTER(feed, CHOOSECOLS(feed, 1) <> ""), or clean the source in Power Query.
GROUPBY or FILTER returns #VALUE! when columns are trimmed separately. Bank!D2:.D20000 and Bank!F2:.F20000 ended at different rows because one column has a blank last cell. Fix: trim the whole block once in LET and pick columns from it with CHOOSECOLS.
The range runs thousands of rows past the data. A stray value sits far below the feed, a note or a test number typed in row 9,000. The trim stops at the last non-empty cell, so it includes everything down to it. Fix: keep notes off the data tab, as never paste over a query output argues for any data landing zone.
The header row appears as data. A whole-column trim reference, A:.F, starts at row 1. Fix: wrap it in DROP(..., 1), or start the reference at row 2.
The result returns #SPILL!. A trim reference typed alone in a cell, =Bank!A2:.F20000, spills the whole block, and something is in the way. Fix: clear the area, or reference the block inside a function rather than displaying it.
TRIMRANGE returns #NAME?, or trim references will not calculate. The file opened in Excel 2024 or earlier, which lacks both. Fix: if the model must travel, load the data into an Excel Table and reference its columns, which every version supports.
Related functions
- TAKE. Once the block is trimmed, TAKE keeps the latest rows. Its sibling DROP removes the header from a whole-column trim reference.
- CHOOSECOLS. Picks columns out of a single trimmed block so every column keeps the same height.
- GROUPBY. The natural consumer of a trimmed raw paste: a summary with no Table and no PivotTable.
- VSTACK. Stack several trimmed entity pastes without empty rows between them.
- FILTER. Removes interior blank rows that trimming leaves in place.
- LET. Name the trimmed block once and read it everywhere in the formula.
- OFFSET. The volatile function trim references replace for dynamic ranges.
