Lookup & reference function

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])
ArgumentWhat it means
rangeRequiredThe range to trim, often a generous range such as A1:B1000 or a whole column.
trim_rowsOptional0 keep all rows, 1 trim leading blank rows, 2 trim trailing blank rows, 3 trim both (default).
trim_colsOptional0 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

D1fx=TRIMRANGE(A1:B6)
ABCDE
1ProductUnitsProductUnits
2Keyboard120Keyboard120
3Mouse340Mouse340
4Webcam85Webcam85

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

D1fx=ROWS(TRIMRANGE(A1:A6))
ABCD
1ProductUnits4
2Keyboard120
3Mouse340
4Webcam85

Result: 4

The trimmed range is A1:A4, which has 4 rows.

3Trim reference shorthand

D1fx=ROWS(A2:.A100)
ABCD
1ProductUnits3
2Keyboard120
3Mouse340
4Webcam85

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.

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 16 KB

Common errors and how to fix them

ErrorWhy it happensFix
#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:.A style 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.

LanguageFunction name
DutchTRIMBEREIK
FinnishRAJAAALUE
Norwegian (Bokmål)TRIMMEOMRÅDE
PolishPRZYTNIJZAKRES
RussianУРЕЗДИАПАЗОН
SpanishRECORTAR.RANGO
TurkishKIRPARALIĞI

Recipes that use TRIMRANGE