TRIMRANGE function
Cuts empty rows and columns off the edges of a range, so formulas only see the part that actually holds data.
Available in Microsoft 365 only (added in 2025), including Excel for the web
Microsoft 365 onlyNot in Google Sheets
Syntax
TRIMRANGE(range, [trim_rows], [trim_cols])| Argument | What it means | |
|---|---|---|
range | Required | The range to trim, often a generous range such as A1:B1000 or a whole column. |
trim_rows | Optional | 0 keep all rows, 1 trim leading blank rows, 2 trim trailing blank rows, 3 trim both (default). |
trim_cols | Optional | 0 keep all columns, 1 trim leading blank columns, 2 trim trailing blank columns, 3 trim both (default). |
Returns: A reference to the smaller range that remains after the blank outer rows and columns are removed.
How TRIMRANGE works
People often point formulas at oversized ranges like A1:B1000 so they keep working as data grows. With dynamic arrays that creates a problem: =A1:B1000 spills a thousand rows of zeros, and functions like TAKE or UNIQUE treat the empty rows as data. TRIMRANGE solves it by shrinking the reference to the block that actually contains values, while still growing automatically when you add rows.
Only blank rows and columns on the outside edges are removed - an empty row in the middle of the data stays. By default both leading and trailing blanks are trimmed; the optional arguments let you trim only one side. Excel also offers a shorthand called trim references: put a dot next to the colon, as in A2:.A1000, to trim trailing blanks (.: trims leading and .:. trims both).
Examples
1Spill only the filled part
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Product | Units | Product | Units | |
| 2 | Keyboard | 120 | Keyboard | 120 | |
| 3 | Mouse | 340 | Mouse | 340 | |
| 4 | Webcam | 85 | Webcam | 85 |
Rows 5 and 6 are empty, so the result is just A1:B4 - no rows of zeros at the bottom.
2Count rows that hold data
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Product | Units | 4 | |
| 2 | Keyboard | 120 | ||
| 3 | Mouse | 340 | ||
| 4 | Webcam | 85 |
Result: 4
The trimmed range is A1:A4, which has 4 rows.
3Trim reference shorthand
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Product | Units | 3 | |
| 2 | Keyboard | 120 | ||
| 3 | Mouse | 340 | ||
| 4 | Webcam | 85 |
Result: 3
The :. operator trims trailing blanks from A2:A100, leaving A2:A4 - three products. Add a product in A5 and the result becomes 4.
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#NAME? | Your Excel version does not have TRIMRANGE yet. | Update Microsoft 365, or use a formatted table or TAKE with COUNTA instead. |
#REF! | The whole range is empty, so there is nothing left after trimming. | Check that the range contains data. |
Tips
- Use
A:.Astyle references in XLOOKUP or UNIQUE to get whole-column convenience without the performance cost of a million blank rows. - Blank cells inside the data are not removed; use FILTER for that.
Google Sheets
Use open-ended ranges such as A2:A together with FILTER(A2:A, A2:A<>"") to drop empty rows.
TRIMRANGE in other languages
In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.
| Language | Function name |
|---|---|
| Dutch | TRIMBEREIK |
| Finnish | RAJAAALUE |
| Norwegian (Bokmål) | TRIMMEOMRÅDE |
| Polish | PRZYTNIJZAKRES |
| Russian | УРЕЗДИАПАЗОН |
| Spanish | RECORTAR.RANGO |
| Turkish | KIRPARALIĞI |