Practice free

TRIMRANGE function

TRIMRANGE returns a range without its empty outer rows and columns, so whole-column references like A:C behave like exactly sized ranges. It trims only the edges, not blanks in the middle.

Example

Read it as a sentence: trim the blank rows off the bottom of column B, then count how many rows are left, which gives 21.

Practice this in the app

Syntax

TRIMRANGE(range, [trim_rows], [trim_cols])

Arguments in [square brackets] are optional.

range (required)
The range to trim.
trim_rows (optional)
Which empty rows to remove: 0 none, 1 leading, 2 trailing, 3 both (default).
trim_cols (optional)
Which empty columns to remove, same codes.

Returns: The range without empty outer rows and columns.

One TRIMRANGE formula can fill more than one cell. When the result has several values, they spill into the cells below or to the right of the formula.

What Excel actually returns

Each formula below was run in desktop Excel. The result is exactly what the cell showed, errors included.

FormulaExcel showsCase
=ROWS(TRIMRANGE(Items!B:B)) 21 Whole column
=COLUMNS(TRIMRANGE(Items!A1:Z1)) 9 Trailing empty columns
=ROWS(TRIMRANGE(Data!F1:F15,1)) 14 Trim leading only
=ROWS(TRIMRANGE(Data!F1:F15,2)) 12 Trim trailing only
=ROWS(Items!B:.B) 21 Trim-ref operator
=TRIMRANGE(Items!B1:E30) #SPILL! Trailing empty rows
=TRIMRANGE(Items!B1:E30,0) #SPILL! Trim none
=TRIMRANGE(Items!B1:E7,4) #VALUE! Bad trim value

The Data sheet these formulas read

A cell that starts with = holds that formula.

Watch out for

  • Only trims edges, not blanks in the middle.
  • There is a shorthand dot syntax (A1.:C100) that does the same trim.

Where it works

Excel
TRIMRANGE is only in Excel for Microsoft 365 and Excel for the web. Recent 365 addition; argument codes written so verify in your build.
Google Sheets
No direct equivalent. No known direct equivalent; unsure whether newer Sheets versions have one.

Part of Lookup and reference functions. Every result on this page was measured in desktop Excel, build 16.0.20527. Last updated .