The beauty of TRIMRANGE is that it will track the data in a worksheet as it changes.

See below for details with examples.

This article is focused on TRIMRANGE, but includes a section on Trim Refsbelow.

The TRIMRANGE function trims from the outside edges in

The result is a “trimmed range” that includes only the data in the original range.

Essentially, trim refs use a dot (.)

together with the colon (:) in a range to add trim behaviors.

The TRIMRANGE function trims from the outside edges in

Personally, I prefer the TRIMRANGE function because it makes the action clear and explicit.

The dot syntax is tricky to read and might not be noticed or understood by many users.

How TRIMRANGE works

It’s important to understand how TRIMRANGE works.

The TRIMRANGE function trims from the outside edges in

Starting from the outer boundary of the range, TRIMRANGE scans inward.

It removes empty leading and trailing rows, and empty leading and trailing columns.

The final result is data in the range B3:H14.

The TRIMRANGE function trims from the outside edges in

What is a dynamic range?

To understand why TRIMRANGE can be useful, you should understand the concept of a dynamic range.

A dynamic range in Excel automatically expands and contracts to track the data it contains.

The TRIMRANGE function trims from the outside edges in

The beauty of this approach is simplicity.

Instead of working out the address of the last row that contains data, we just provide columns.

However, we must be careful because Excel worksheets are very large each worksheet contains over 1 million rows.

TRIMRANGE Example - trimming a large range

Essentially, TRIMRANGE allows us to have our cake and eat it too.

We can use simple references and let TRIMRANGE figure out which cells contain data.

More commonly, you will pipe the result of TRIMRANGE into another function.

Static ranges - these formulas are not dynamic

By default, TRIMRANGE trims empty rowsand columnsfrom a range.

The table that holds the property listings appears in the range B4:H14.

The first row is a header row, so the actual data range is B5:H14.

Static ranges do not adapt to the new data

This doesn’t quite work in this case because we are including the header row together with the data.

We can solve that problem by adding the DROP function to drop the first row.

The next logical step is to create a dynamicnamedrange.

TRIMRANGE Example - simple dynamic range

One way to do that is to create anamed range.

A named range is simply a human-readable name assigned to a range.

Because formulas respond to changes in a worksheet, we call this a “dynamic named range”.

Naming a range defined by a formula

The first step is to define a name.

This is because we need to the reference to work the same from any cell in the workbook.

First, we have reduced redundant code in our formulas.

TRIMRANGE Example - dynamic named range called “data”

As before, the range is fully dynamic and will adapt as the worksheet is changed.

Because we are using TRIMRANGE, these formulas are dynamic and will instantly update when products or colors change.

Note we are not using TRIMRANGE to create a dynamic named range in this case but we could.

TRIMRANGE Example - create a dropdown menu

For more details on Data Validation, seethis page.

Example - Anchoring other formulas

Another use of TRIMRANGE is to “anchor” other formulas.

What does this mean, exactly?

TRIMRANGE Example - create a dropdown menu for products

This is convenient because we get all 1 results with a single formula.

With TRIMRANGE, naturally .

In the worksheet below, we have the original formula in cell D5.

TRIMRANGE Example - create a dropdown menu for colors

However, remember that TRIMRANGE trims the rangefirst, before DROP gets involved.

There are different ways to handle this kind of problem.

Key benefits of TRIMRANGE

TRIMRANGE is a technical function designed for more advanced users.

One dynamic array formula returns 11 results

The number of rows and columns to remove is provided by separaterowsandcolumnsarguments.

By default, TOCOL will scan values by row, but TOCOL can also scan values by column.

TOROW Function

The Excel TOROW function transforms an array into a single row.

The dynamic array formula does not automatically expand

By default, TOROW will scan values by row, but TOROW can also scan values by column.

TRIMRANGE Example - anchoring other formulas to data

Excel formula: Sum last n rows

Excel formula: Dynamic named range with OFFSET

Excel formula: Sum last n columns

Excel formula: Dynamic named range with INDEX

Excel DROP function

Excel TOCOL function

Excel TOROW function

The TRIMRANGE function trims from the outside edges in

TRIMRANGE Example - trimming a large range

Static ranges - these formulas are not dynamic

Static ranges do not adapt to the new data

TRIMRANGE Example - simple dynamic range

TRIMRANGE Example - dynamic named range called “data”

TRIMRANGE Example - create a dropdown menu

One dynamic array formula returns 11 results

The dynamic array formula does not automatically expand

TRIMRANGE Example - anchoring other formulas to data