TRIMRANGE Function¶
The TRIMRANGE function in Excel is used to remove empty rows and columns from the edges of an array or range. It trims leading and trailing blank rows and columns, returning a more compact array without affecting internal data.
Key Features of TRIMRANGE:¶
- Removes empty rows from the top and bottom of an array.
- Removes empty columns from the left and right of an array.
- Preserves all internal data, including embedded blank cells.
- Works seamlessly with other dynamic array functions.
- Useful for cleaning up data ranges before further processing.
Syntax:¶
- array: The array or range from which to remove empty rows and columns at the edges.
How TRIMRANGE Works:¶
- The function examines the input array from all four edges (top, bottom, left, right).
- It identifies rows that are entirely empty at the top and bottom of the array.
- It identifies columns that are entirely empty at the left and right of the array.
- These empty edge rows and columns are removed from the result.
- All internal data, including any blank cells within the data region, is preserved.
- If the entire array is empty,
TRIMRANGEreturns an empty result.
Examples:¶
1. Basic Trimming of a Range with Empty Edges:¶
If A1:D6 contains data with the first row and last column empty:
Result:
2. Trim a Range with Empty Rows at Top and Bottom:¶
If A1:C5 has empty rows 1 and 5:
Result:
3. Trim a Range with Empty Columns on Both Sides:¶
If A1:E3 has empty columns A and E:
Result:
4. Combine with HSTACK to Clean Up Combined Arrays:¶
Result:
5. Combine with VSTACK for Vertical Stacking:¶
Result:
6. Clean Up Results from EXPAND:¶
Result:
7. Use with IF to Conditionally Include Data:¶
Result:
8. Trim a Literal Array:¶
Result:
(Rows with only empty strings are trimmed)Notes:¶
TRIMRANGEis available in Excel 365 and Excel 2021 or later versions.- The function only removes completely empty rows and columns at the edges; internal blanks are preserved.
- Cells containing spaces or formulas returning empty strings ("") are considered empty for trimming purposes.
TRIMRANGEis particularly useful after operations likeFILTER,EXPAND, orIFthat may create sparse arrays.- The function does not modify the original data; it creates a new trimmed array.
Applications:¶
- Data Cleanup: Remove extraneous empty rows and columns before analysis or export.
- Dynamic Reporting: Ensure reports only include populated areas of data.
- Array Optimization: Reduce array size after combining or filtering operations.
- Formula Chaining: Clean up intermediate results in complex dynamic array formulas.
- Data Import: Process imported data that may have irregular empty edges.
Related Functions:¶
- EXPAND: Increases array dimensions by adding rows and/or columns with padding.
- TAKE: Extracts a specified number of rows or columns from an array.
- DROP: Excludes a specified number of rows or columns from an array.
- HSTACK: Horizontally combines arrays side by side.
- VSTACK: Vertically stacks arrays on top of each other.
- FILTER: Filters a range based on criteria, which may leave empty areas.
- TOCOL: Converts an array to a single column.
- TOROW: Converts an array to a single row.
Tip: Use
TRIMRANGEafter combining multiple arrays withHSTACKorVSTACKto ensure the final result contains no unnecessary empty edges, especially when working with data of varying sizes.