The TRIMRANGE function scans from the edge of a range or array until it finds non-blank cells (or values), and then excludes those blank rows or columns.
Syntax
=TRIMRANGE(range,[trim_rows],[trim_cols])
Argument | Description |
---|---|
range | (Required) The range (or array) to be trimmed. |
trim_rows | (Optional) Determines which rows should be trimmed. 0 - None. 1 - Trims leading blank rows. 2 - Trims trailing blank rows. 3 - Trims both leading and trailing blank rows (default). |
trim_cols | (Optional) Determines which columns should be trimmed. 0 - None. 1 - Trims leading blank columns. 2 - Trims trailing blank columns. 3 - Trims both leading and trailing blank columns (default). |
Samples
sheet.setFormula(0, 0, "TRIMRANGE(A:C, 3, 0)");
Trim References
Trim References (aka Trim Refs) are a set of shorthand notations that allow you to trim blank rows and columns from a range without having to use the TRIMRANGE function explicitly. Trim Refs modify the traditional colon (:) range operator by adding dots (.) to specify how you want to trim the range. There are three types of Trim Refs:
Trim Ref Type | Syntax | Equivalent TRIMRANGE | Description |
---|---|---|---|
Trim All | A1.:.E10 | =TRIMRANGE(A1:E10, 3, 3) | Trims both leading and trailing blanks from the range. |
Trim Trailing | A1:.E10 | =TRIMRANGE(A1:E10, 2, 2) | Trims only the trailing blanks from the range. |
Trim Leading | A1.:E10 | =TRIMRANGE(A1:E10, 1, 1) | Trims only the leading blanks from the range. |
Submit and view feedback for