Back to functions
Lookup & Reference2026-11-161 related article

TRIMRANGE Function in Excel

Remove empty rows or columns from the outer edges of a range while keeping the data and any internal gaps.

Syntax

TRIMRANGE(range,[trim_rows],[trim_cols])
Table of Contents

Arguments

range

Required

The range or array whose outer empty rows and columns you want to remove.

trim_rows

Optional

Choose 0 to keep all rows, 1 to trim leading empty rows, 2 to trim trailing empty rows, or 3 to trim both ends. The default is 3.

trim_cols

Optional

Choose 0 to keep all columns, 1 to trim leading empty columns, 2 to trim trailing empty columns, or 3 to trim both ends. The default is 3. Microsoft calls this argument trim_columns in its argument table.

What it returns

A range or array with the selected empty outer rows and columns removed. Gaps inside the retained range remain in place.

What TRIMRANGE does

TRIMRANGE removes empty rows and columns from the edges of a range. It's useful when a list has room for more entries but you want a formula to return only the occupied part. You choose which edges to trim; the source cells stay where they are.

For a vertical list, use the second argument to control rows and set the third argument to 0 to keep columns. Omitting both optional arguments trims empty edges in both directions.

Practical examples

Remove empty rows above and below a team list

Set up A2:A7 as follows. Leave the cells marked empty genuinely empty; don't type that word or a space into them.

CellContents
A2empty
A3Design
A4Finance
A5Support
A6empty
A7empty

With C3:C5 clear, enter this in C3:

=TRIMRANGE(A2:A7,3,0)
Formula

The expected result fills C3:C5:

Design
Finance
Support
Example

The 3 removes empty rows at both ends: A2 above the list, and A6:A7 below it. The 0 leaves the column dimension alone.

Keep a fixed starting row and trim the unused tail

Use the same data, but start the source at A3, where the first team name belongs. With E3:E5 clear, enter this in E3:

=TRIMRANGE(A3:A7,2,0)
Formula

The expected result fills E3:E5:

Design
Finance
Support
Example

The 2 removes only trailing empty rows. Excel starts at the bottom of A3:A7, excludes A7 and A6, and keeps A3:A5. If the first source row becomes empty, this setting won't trim it from the top.

The updating a list without OFFSET tutorial uses this trailing-row setting in a defined name for a bounded drop-down source, with the setup and tested-build limits explained beside the formula.

Common mistakes and notes

Internal gaps stay in the range

TRIMRANGE trims the outside of a range; it doesn't remove individual empty cells between entries. Clearing A4 in the examples leaves a position between Design and Support. Use a filtering operation if your task requires a compact list with those gaps removed.

A cell that looks empty may contain something

The examples use cells with no contents. A space and a formula returning "" are different inputs. In the linked tutorial's tested named drop-down source, either one at the trailing edge kept an extra visually blank choice. Clear the cell's contents when you want a genuinely empty trailing cell.

The source boundary still matters

Both examples stop at A7. An entry added in A8 is outside those references and won't appear in their results. Allow enough room in the source range for the entries you expect, or use a Table-based approach when the source itself needs to expand.

Leave room for the result and check availability

The worksheet examples return three rows into neighboring cells, so keep the output area clear. Microsoft's current Applies To list names Excel for Microsoft 365. Check that your Excel recognizes TRIMRANGE before using it in a shared workbook; the linked drop-down tutorial records the specific Mac build tested for that method.

Related functions

Related articles

Deep dives, troubleshooting guides, and practical examples that use TRIMRANGE.

Official documentation