Ranges function

TRIMRANGE

Cut the empty rows off a range.

Purpose

Cut the empty rows and columns off the outside of a range

Returns

The same block with its empty outside rows and columns dropped

Syntax

=TRIMRANGE(range, [trim_rows], [trim_columns])

ArgumentRequiredWhat goes here
rangeRequiredThe block to trim, written generously, like B5:B1000.
trim_rowsOptional1 cuts the empty rows above the data, 2 the ones below, 3 both. 3 if you leave it out.
trim_columnsOptionalSame three choices, applied to empty columns instead of rows.

How to use TRIMRANGE

A formula written over exactly the rows that are there today has to be rewritten the moment a row is added. A formula written over a generous block, B5 to B1000, keeps working and drags nine hundred empty rows into every calculation.

TRIMRANGE settles that. It takes the generous block and hands on only the part with data in it, working inwards from the edges.

Only whole empty rows and columns on the outside go. A gap left in the middle of the data stays exactly where it is, which is what you want: a missing amount is a fact about the ledger, not something to tidy away.

The dot operator is the same thing in less space. B5:.B1000 trims the trailing edge, B5.:B1000 the leading one, and B5.:.B1000 both. The dot sits on the side of the colon it trims.

Which to write is a matter of taste. TRIMRANGE names itself in the formula and reads more clearly to somebody who has not met the dot before.

It changes nothing about a plain SUM, because SUM was ignoring the blanks anyway. It changes everything about counting gaps, and about any formula that produces one result per row.

Examples

Every result below is worked out by the same evaluator that marks your answers, on the sheet shown here.

Payables ageing — October.xlsxSheet1
Harbour Foods payables at 31 October 2026, with supplier terms alongside
ABCDEFGH
1InvoiceSupplierStatusDays overdueAmountSupplierTerms (days)
2INV-8801Brightwell PaperOverdue12940Ashgrove Catering30
3INV-8802Calder UtilitiesQueried471180Brightwell Paper30
4INV-8803Meridian FreightOverdue632450Calder Utilities14
5INV-8804Ashgrove CateringOn terms0405Meridian Freight45
6INV-8805Brightwell PaperOverdue38760Thornbury Print60
7INV-8806Thornbury PrintOverdue911320
8INV-8807Meridian FreightOn terms0580
9INV-8808Calder UtilitiesOverdue24215
FormulaResult
=COUNTBLANK(E2:E40)A completeness check written over a generous block. It reports thirty-one gaps, every one of them a row that does not exist yet.31
=COUNTBLANK(TRIMRANGE(E2:E40))The same check with the empty rows trimmed off first. Nought gaps, which is the true answer, and it stays true as the ledger grows.0
=COUNTBLANK(E2:.E40)The dot operator saying the same thing. The dot goes after the colon, on the side of the range being trimmed.0
=SUM(TRIMRANGE(E2:E40))A total is the same either way, because SUM never counted the blanks. This is why trimming looks pointless until you meet a formula that does count them.7850
=COUNT(E2:.E40)/COUNTA(A2:.A40)What proportion of the rows carry a figure. Neither half of this works over a fixed range once rows are added, and neither works over an untrimmed generous one.1

Notes

  • Trim every range in a formula or none of them. A SUMIFS whose totalling column is trimmed and whose tested column is not will refuse, and that refusal is doing you a favour.
  • TRIMRANGE takes an optional code for each axis: 1 trims the leading edge, 2 the trailing edge, 3 both, 0 neither. It is 3 unless you say otherwise.
  • Both the dot operator and TRIMRANGE arrived in Excel in 2024, so a file using them will not open in an older version.
Practise TRIMRANGE in Unit 28

A reference tells you what it does. A unit makes you use it.