Google Sheets function · Array
TOCOL in Google Sheets: syntax and examples
TOCOL stacks all values of a range or array into a single column. It can drop blanks and errors on the way and read either row by row or column by column.
Syntax
TOCOL(array_or_range, [ignore], [scan_by_column])
Arguments
| Argument | Type | Required | What it does |
|---|---|---|---|
array_or_range | range | yes | The array or range to flatten into one column. |
ignore | number | no | 0 keeps everything (default), 1 skips blanks, 2 skips errors, 3 skips both. |
scan_by_column | boolean | no | FALSE (default) reads row by row. TRUE reads column by column. |
Examples
The examples use this table, starting in A1:
| 1 | 2 | 3 |
| 4 | 6 |
=ROWS(TOCOL(A1:C2))Result: 6
The empty cell keeps its own row: six cells in, six rows out.
Run in a Google Sheet (English US locale) on .
=TOCOL(A1:C2, 1)Result:
| 1 |
| 2 |
| 3 |
| 4 |
| 6 |
Same range, blanks skipped.
Run in a Google Sheet (English US locale) on .
=TOCOL(A1:C2, 1, TRUE)Result:
| 1 |
| 4 |
| 2 |
| 3 |
| 6 |
Blanks skipped and the scan goes down each column first: 1, 4, 2, 3, 6.
Run in a Google Sheet (English US locale) on .
=SUM(TOCOL(A1:C2, 1))Result: 16
Wrapped in another function, the single column is easy to aggregate.
Run in a Google Sheet (English US locale) on .
=TOCOL({1,2;3,4})Result:
| 1 |
| 2 |
| 3 |
| 4 |
Works on an array literal too.
Run in a Google Sheet (English US locale) on .
Common errors
- By default blank cells are kept, so the output has as many rows as the range has cells. Use ignore 1 to drop them.
- ignore 1 removes only blanks. Errors stay in the output until you use 2.
- The default scan is row by row. If the order matters, set scan_by_column to TRUE and check the first values.
- The ignore argument only accepts 0 to 3. A value such as 4 returns #VALUE!.
Compared with Excel
Excel 365 has TOCOL with the same arguments.