TRIMRANGE Function in Excel: Drop Empty Rows From a Range
By ExcelReady TeamUpdated 6 min read
The short answer
TRIMRANGE removes empty rows and columns from the outer edges of a range, so =UNIQUE(TRIMRANGE(A2:A1000)) only looks at the rows that hold data. It does not remove blank rows in the middle: use FILTER for that. TRIMRANGE and the shorter trim reference A2:.A1000 are recent Microsoft 365 features.
Key takeaways
- TRIMRANGE(range, [trim_rows], [trim_cols]) cuts empty rows and columns from the edges of a range.
- It only trims leading and trailing blanks. Blank rows inside the data stay; FILTER removes those.
- Trim references are a shortcut: A2:.A1000 trims trailing blanks, like TRIMRANGE(A2:A1000,2).
- It is useful with UNIQUE, SORT and whole-column references, which otherwise pick up empty cells.
- TRIMRANGE is a recent Microsoft 365 addition; in other versions, use FILTER or an Excel table.
On this page+
The TRIMRANGE function in Excel removes empty rows and columns from the outer edges of a range, so formulas only see the part that holds data. Write =TRIMRANGE(A2:A1000) and, if data fills A2:A6, you get A2:A6. It is useful whenever you point a formula at a big range "to leave room for new rows" and then get zeros or blanks in the result. This guide covers the syntax, the shorter trim references, what TRIMRANGE does not do, and what to use in older versions.
What problem does TRIMRANGE solve?#
Many people use oversized ranges, such as A2:A1000 or the whole column A:A, so new rows are included without editing the formula. With dynamic array functions, that creates problems:
- UNIQUE returns an extra 0. The empty cells count as one more "unique" value, shown as 0.
- SORT puts blanks or zeros in the result, and the spill is far longer than the data.
- Whole-column formulas do extra work, because Excel has to consider up to 1,048,576 rows.
TRIMRANGE fixes this by cutting the empty edge off the range before the other function sees it. The guide to dynamic arrays in Excel explains spilling, and the modern Excel functions lesson lets you practise UNIQUE, SORT and FILTER.
TRIMRANGE syntax#
TRIMRANGE has one required argument and two optional ones:
=TRIMRANGE(range, [trim_rows], [trim_cols])| Argument | What it means |
|---|---|
| range | The range to trim, such as A2:A1000 or A:C |
| trim_rows | 0 = keep all rows, 1 = trim leading blank rows, 2 = trim trailing blank rows, 3 = trim both (default) |
| trim_cols | The same choices for columns; default 3 |
With these regions in column A:
| A | |
|---|---|
| 1 | Region |
| 2 | North |
| 3 | South |
| 4 | North |
| 5 | East |
| 6 | South |
| 7 | |
| 8 | |
| 9 |
=UNIQUE(A2:A9) returns North, South, East and 0: four rows, one of them the blank. =UNIQUE(TRIMRANGE(A2:A9)) returns just North, South and East, because the range is trimmed to A2:A6 first.
TRIMRANGE treats a cell as empty only if it is truly empty. A cell with a space, or a formula that returns "", counts as data and is not trimmed.
How to use trim references like A:.A#
Trim references are a shorter way to write the same thing. You add a dot next to the colon of a normal range:
| Reference | Trims | Same as |
|---|---|---|
A2:.A1000 | Trailing empty rows and columns | TRIMRANGE(A2:A1000,2,2) |
A2.:A1000 | Leading empty rows and columns | TRIMRANGE(A2:A1000,1,1) |
A2.:.A1000 | Both | TRIMRANGE(A2:A1000,3,3) |
The trailing version is the one you will use most. =UNIQUE(A2:.A1000) lists each region once with no 0 at the end, and =SORT(A:.A) sorts column A down to the last used cell. Think of the dot as being on the side you want trimmed.
TRIMRANGE does not remove blanks in the middle#
This is the most common misunderstanding. TRIMRANGE only trims the edges of the range. If row 4 were blank between North and East, TRIMRANGE would keep it, because it sits inside the data.
To drop every empty row, wherever it is, use FILTER:
=FILTER(A2:A9,A2:A9<>"")FILTER keeps only the rows where the condition is TRUE, and <>"" means "not empty". It returns North, South, North, East and South. Combine it with UNIQUE for a clean list, and with ROWS to count it:
=ROWS(UNIQUE(FILTER(A2:A9,A2:A9<>"")))The result is 3 distinct regions. The FILTER function guide explains each argument, and the article on filtering out blank cells covers more cases, such as rows where any column is empty.
When to use TRIMRANGE vs FILTER vs a table#
Each tool fits a different situation:
| Situation | Best choice |
|---|---|
| Data grows at the bottom, no gaps inside | TRIMRANGE or a trim reference |
| Blank rows can appear anywhere | FILTER with <>"" |
| You control the data layout | An Excel table (Ctrl+T on Windows, ⌘T on a Mac) |
| You need the first or last N rows | TAKE or DROP |
Excel tables are often the cleanest answer: a structured reference such as Table1[Region] grows and shrinks with the data, in every version since Excel 2007. TRIMRANGE helps when the data can't be a table, such as a range filled by another process. To return a fixed number of rows instead, see the TAKE function guide.
Which Excel versions have TRIMRANGE?#
TRIMRANGE and trim references are a recent addition to Microsoft 365. They appeared first for Microsoft 365 Insiders and then rolled out to subscribers on Windows, Mac and the web, so a Microsoft 365 install that hasn't updated recently may not have them yet. Perpetual versions such as Excel 2021 don't have them, and as far as Microsoft's version notes show, neither does Excel 2024. To check your own Excel, type =TRIMR in a cell: if TRIMRANGE appears in the list, you have it.
If you share a file with someone on an older version, TRIMRANGE formulas show a #NAME? error on their computer. For shared files, FILTER (Excel 2021 and Microsoft 365) or a table is the safer choice.
Common TRIMRANGE mistakes#
Check these if the result isn't what you expect:
- Expecting middle blanks to go. TRIMRANGE trims edges only. Use FILTER.
- "Empty-looking" cells. A space or a
""formula stops the trim. Clear those cells or use FILTER. - #SPILL! errors. The trimmed result still spills; make sure the cells below the formula are empty. The guide to referencing a spill range explains the
#operator. - Writing the dot in the wrong place.
A2.:A1000trims leading blanks, not trailing ones. - Using it in a file for older versions. Other people will see #NAME?.
Practise it#
TRIMRANGE is one of several newer functions built for dynamic arrays, and FILTER is the one you will use most. Practise the FILTER function in a live spreadsheet, then practise UNIQUE, SORT and other modern Excel functions: you type the formula and it checks it instantly. Or try the exercise on this page and count the regions without the blank.
Try it yourself
This is a live spreadsheet. Type the formula in the green cell and press Enter.
The Region list in A2:A9 has blank rows at the end. =ROWS(UNIQUE(A2:A9)) returns 4, because the blank counts as a region. In C2, count the distinct regions without the blank: wrap A2:A9 in FILTER to keep non-empty cells, then UNIQUE, then ROWS. Press Enter.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Region | |||
| 2 | Distinct regions | |||
| 3 | South | |||
| 4 | North | |||
| 5 | East | |||
| 6 | South | |||
| 7 | ||||
| 8 | ||||
| 9 |
Tip: FILTER(A2:A9,A2:A9<>"") keeps only filled cells. Put that inside UNIQUE, and UNIQUE inside ROWS.
Practise this in a lesson
Frequently asked questions
What does the TRIMRANGE function do in Excel?
It returns a range with the empty rows and columns at its outer edges removed. For example, if data fills A2:A6, TRIMRANGE(A2:A1000) returns just A2:A6.
Does TRIMRANGE remove blank rows in the middle of data?
No. It only trims empty rows and columns at the start and end of the range. To remove every blank row, use FILTER, such as =FILTER(A2:A100,A2:A100<>"").
What does A:.A mean in Excel?
It is a trim reference. The dot after the colon trims empty rows from the end of the range, so A:.A means column A down to the last used cell. A.:A trims leading blanks and A.:.A trims both.
Which Excel versions have TRIMRANGE?
TRIMRANGE and trim references are a recent addition to Microsoft 365. Older perpetual versions such as Excel 2021 don't have them. If typing =TRIMRANGE( shows no tooltip, your version doesn't support it.
Why does UNIQUE return a 0 at the end of the list?
The range includes empty cells, and UNIQUE returns one empty value, which shows as 0. Trim the range with TRIMRANGE, or filter out blanks with FILTER before UNIQUE.