The elements are visited in one of two traversal orders and, optionally, filtered by kind
before being laid out left to right:
scan_by_column omitted or FALSE — scan by row: row 1 left to right, then row 2, and
so on (row-major).
scan_by_columnTRUE — scan by column: column 1 top to bottom, then column 2
(column-major).
For {1,2;3,4} those give {1,2,3,4} and {1,3,2,4}.
The ignore argument drops element kinds before assembly, with the same code vocabulary the
whole flattening pair shares: 0 keep everything (default), 1 ignore blanks, 2 ignore
errors, 3 ignore both.
TOROW and TOCOL are the same operation with the output axis exchanged;
TOROW(x, i, s) equals TRANSPOSE(TOCOL(x, i, s)). Which one you want is decided by what
consumes the result, not by anything about the input.
Arguments
Microsoft documents TOROW(array, [ignore], [scan_by_column]).
array — required. The array or reference to flatten.
ignore — optional, default 0. Values 0–3 as above. It is an integer code, not a
logical, even though 1 and TRUE coerce alike.
scan_by_column — optional, default FALSE. A logical selecting the traversal order.
The common confusion is between the two optional positions: TOROW(A, 1) filters blanks;
TOROW(A, , 1) changes the traversal. Both are legal and neither errors, so the mistake shows
up as a silently reordered or silently shortened row.
A second confusion is specific to this function's name. TOROW does not mean "read the
array by rows" — that is scan_by_columnFALSE. It means "produce a row". The name describes
the output shape; the traversal is the third argument's business.
Try it
Quirks
Result and edge cases
The return kind is a single-row array.
The result can be empty when ignore removes everything; Excel's convention for an empty
array result is #CALC! (the value universe), and TOROW
uses it with ignore2 when nothing is left (FN-HSTACK-001).
"Blank" is ambiguous between an empty cell and text of zero length. Which one ignore1 drops is the question that decides how the function behaves on formula-generated data,
and the documentation does not disambiguate it.
Ignoring errors shortens the result; positions no longer correspond to source cells. A
direct error is not an element and is not ignored (FN-HSTACK-001).
A one-element result stays an array.
Dynamic-array publication and #SPILL! are host-side adaptation.
Errors
Microsoft's TOCOL page documents #VALUE! for an array constant containing numbers that are
not whole numbers, and #NUM! for an array that is too large. TOROW is documented as the
twin function and the same conditions are the expected ones; the Handbook has not confirmed
that the TOROW page states them identically, and does not assert the first condition's
meaning, which does not obviously describe a flattening operation.
A direct error stops these array functions; the same error in an array or cell is an element
An error written directly as an argument of these functions is the answer for the whole call. It is not placed in the result: HSTACK(1,#VALUE!) is #VALUE!, not a row holding 1 and an error, and TAKE(#N/A,0) is #N/A. With MAP the LAMBDA does not run at all: MAP(NA(),LAMBDA(xx,IFERROR(xx,3))) is #N/A. The same error inside an array, or in a referenced cell, is an ordinary element: MAP({#N/A},LAMBDA(xx,3)) is 3, and HSTACK(Data!C1,{1;2}) with #N/A in Data!C1 is a 2 by 2 array with #N/A in its first column. TOCOL and TOROW show the difference with ignore 2: TOCOL(#N/A,2) is #N/A, while TOCOL({#N/A},2) drops the error, has nothing left, and is #CALC!. EXPAND is an exception on the cell side: EXPAND(Data!C1,2,2,"pad") is #N/A for the whole call. BYROW and BYCOL check the direct error first too: BYROW(#N/A,#VALUE!) is #N/A, while BYROW({#N/A},2), where 2 is not a LAMBDA, is #VALUE!.
Formula
Excel
Mathematical value
=HSTACK(1,#VALUE!) Excel 16.0.20527.20088 Current Channel, Windows 64-bit (NT 10.0.26200), x86-64, AMD Ryzen 7 4800H, en-ZAInputs and reference value
Typed formula.
#VALUE!
—
=TAKE(#N/A,0) Excel 16.0.20527.20088 Current Channel, Windows 64-bit (NT 10.0.26200), x86-64, AMD Ryzen 7 4800H, en-ZAInputs and reference value
Typed formula.
#N/A
—
=MAP(NA(),LAMBDA(xx,IFERROR(xx,3))) Excel 16.0.20527.20088 Current Channel, Windows 64-bit (NT 10.0.26200), x86-64, AMD Ryzen 7 4800H, en-ZAInputs and reference value
Typed formula.
#N/A
—
=MAP({#N/A},LAMBDA(xx,3)) Excel 16.0.20527.20088 Current Channel, Windows 64-bit (NT 10.0.26200), x86-64, AMD Ryzen 7 4800H, en-ZAInputs and reference value
Typed formula.
3 0x4008000000000000
—
=HSTACK(Data!C1,{1;2}) Excel 16.0.20527.20088 Current Channel, Windows 64-bit (NT 10.0.26200), x86-64, AMD Ryzen 7 4800H, en-ZAInputs and reference value
Number supplied through a cell.
Data!C1: #N/A
{#N/A,1;#N/A,2}
—
=TOCOL(#N/A,2) Excel 16.0.20527.20088 Current Channel, Windows 64-bit (NT 10.0.26200), x86-64, AMD Ryzen 7 4800H, en-ZAInputs and reference value
Typed formula.
#N/A
—
=TOCOL({#N/A},2) Excel 16.0.20527.20088 Current Channel, Windows 64-bit (NT 10.0.26200), x86-64, AMD Ryzen 7 4800H, en-ZAInputs and reference value
Typed formula.
#CALC!
—
=EXPAND(Data!C1,2,2,"pad") Excel 16.0.20527.20088 Current Channel, Windows 64-bit (NT 10.0.26200), x86-64, AMD Ryzen 7 4800H, en-ZAInputs and reference value
Number supplied through a cell.
Data!C1: #N/A
#N/A
—
=BYROW(#N/A,#VALUE!) Excel 16.0.20527.20088 Current Channel, Windows 64-bit (NT 10.0.26200), x86-64, AMD Ryzen 7 4800H, en-ZAInputs and reference value
Typed formula.
#N/A
—
=BYROW({#N/A},2) Excel 16.0.20527.20088 Current Channel, Windows 64-bit (NT 10.0.26200), x86-64, AMD Ryzen 7 4800H, en-ZAInputs and reference value
The output axis and the traversal axis are independent. Writing TOROW as "transpose, then
TOCOL" is correct but changes which traversal flag means what — the composition has to be
worked out rather than assumed.
ignore is a code with four admitted values; anything else needs a decided outcome.
The blank definition must be stated explicitly and shared with TOCOL.
Filtering must preserve traversal order.
Rust code
Show the CalcFunc source of this function
Quoted from the public repository DnaCalc/DnaCalc, crates calc-func and calc-fml, at commit 9e1884369a67. Comments are the source's own. A kernel shared with other functions appears once, on its module page.