How to use the TOROW function
What is the TOROW function?
The TOROW function rearranges values from a 2D cell range to a single row.
Dynamic array formula in cell B8:
What Excel version has the TOROW function?
The TOROW function is available to Excel 365 subscribers.
What category is the TOROW function?
The TOROW functionis in the "Array manipulation" category.
How do I enter an Excel 365 dynamic array formula?
A dynamic array formula is entered as a regular formula, however, it spills array values automatically to adjacent cells below or to the right or both.
Table of Contents
1. Syntax
The TOROW function has three arguments, the first one array is required, the remaining two ignore and scan_by_col is optional.
TOROW(array, [ignore], [scan_by_col])
2. Arguments
array | Required. The source cell range or array. |
[ignore] | Optional. Ignore specified values. 0 - keep all values (default) 1 - ignore blanks 2 - ignore errors 3- ignore blanks and errors |
[scan_by_col] | Optional. How the function fetches the values from the source. FALSE - by row (default). TRUE - by column. |
3. Example
The graphic above shows how the TOROW function rearranges values to fit a single row; in its default form, it obtains values by row. This means that it gets the values from the first row then the second row and so on until all rows have been scanned and processed.
Dynamic array formula in cell B8:
The TOROW function is useful for resizing an array to a single row. It is an Excel 365 function and spills values to the cell below and to the cells to the right. A #SPILL! error shows up if the destination cells are not empty. Make sure you delete old values to make it work properly.
3.1 Explaining formula
Tip! You can follow the formula calculations step by step by using the "Evaluate" tool located on the Formula tab on the ribbon. This makes it easier to spot errors and understand the formula in greater detail. The following steps shows the calculations in great detail.
Step 1 - TOROW function
TOROW(array, [ignore], [scan_by_col])
Step 2 - Populate arguments
array - B2:E4
Step 3 - Evaluate function
TOROW(B2:E4)
becomes
TOROW({89, 68, 19, 37;
27, 84, 92, 63;
26, 98, 62, 45})
and returns
{89; 68; 19; 37; 27; 84; 92; 63; 26; 98; 62; 45}
4. Example - by column
The picture above demonstrates how the TOROW function rearranges the values to fit a single row, this example shows it fetching values column by column. Default value is FALSE which means by row.
Dynamic array formula in cell B8:
This example shows in great detail how the TOROW function scans the source array by column and then returns the output to single row.
4.1 Explaining formula
Step 1 - TOROW function
TOROW(array, [ignore], [scan_by_col])
Step 2 - Populate arguments
array - B2:E4
[scan_by_col]) - TRUE
Step 3 - Evaluate function
TOROW(B2:E4, , TRUE)
becomes
TOROW({89, 68, 19, 37;
27, 84, 92, 63;
26, 98, 62, 100})
and returns
{89, 27, 26, 68, 84, 98, 19, 92, 62, 37, 63, 45}
The comma is a column delimiting character, the semicolon is a row delimiting character. You may have other delimiting characters, it depends on your regional settings.
Which delimiting values do I use?
- Double press with left mouse button on an empty cell.
- Type = (equal sign).
- Select a cell range containing two rows and two columns. They can be empty, it doesn't matter.
- Press F9 to convert the cell reference to constants.
- The array that appears shows your delimiting characters.
5. Example - blanks and errors
The image above demonstrates what happens when your source data has empty values and errors.
The result is a horizontal array containing a 0 (zero) instead of empty values, and the error values are not ignored but kept.
Dynamic array formula in cell B8:
The picture above shows how to handle blanks and error values. The second argument lets you determine the outcome for blank and error values.
Here are all valid numbers for the second argument:
0 - keep all values (default)
1 - ignore blanks
2 - ignore errors
3- ignore blanks and errors
Dynamic array formula in cell B8:
5.1 Explaining formula
TOROW(array, [ignore], [scan_by_col])
TOROW(B2:E4, 3)
becomes
TOROW({89, "", 19, 37;
27, 0, 92, 63;
26, 98, 62, #N/A}
)
and returns
{89, 19, 37, 27, 84, 92, 63, 26, 98, 62}
6. Alternative
The following formula rearranges values so they fit a single column, however, the formula doesn't return an array of values. It extracts each value one by one using relative cell references.
You need to copy the cell and paste as far as needed to the right. This formula works in most Excel versions, I recommend the TOROW function if you are a Excel 365 subscriber.
Formula in cell B7:
This formula shows how much effort is needed to resize an array to a single row in earlier Excel versions. The TOROW function shows progress is being made in Excel.
6.1 Explaining formula
Tip! You can follow the formula calculations step by step by using the "Evaluate" tool located on the Formula tab on the ribbon. This makes it easier to spot errors and understand the formula in greater detail. The following steps shows the calculations in great detail.
Step 1 - Calculate the number of columns in a given cell range
The COLUMNS function returns the number of columns in a given cell range.
COLUMNS(array)
COLUMNS($B$2:$E$4)
returns 4.
Step 2 - Calculate column number of relative cell reference
The COLUMN function returns the column number of the top-left cell of a cell reference.
COLUMN(reference)
COLUMN(A1)-1
becomes
1-1 equals 0 (zero)
Step 3 - Calculate row number
The QUOTIENT function returns the integer portion of a division.
QUOTIENT(numerator, denominator)
QUOTIENT(COLUMN(A1)-1, COLUMNS($B$2:$E$4))+1
becomes
QUOTIENT(0, 4)+1
becomes
0+1 equals 1.
Step 4 - Calculate column number
The MOD function returns the remainder after a number is divided by a divisor.
MOD(number, divisor)
MOD(COLUMN(A1)-1, COLUMNS($B$2:$E$4))+1
becomes
MOD(0, 4)+1
becomes
0 + 1 equals 1.
Step 5 - Get value
The INDEX function returns a value from a cell range, you specify which value based on a row and column number.
INDEX(array, [row_num], [column_num], [area_num])
INDEX($B$2:$E$4, QUOTIENT(COLUMN(A1)-1, COLUMNS($B$2:$E$4))+1, MOD(COLUMN(A1)-1, COLUMNS($B$2:$E$4))+1)
becomes
INDEX($B$2:$E$4, 1, 1)
and returns 89 in cell B7.
7. Example - values in random order
The image above shows a formula that returns values to a single row in random order. Cell range B2:E4 contains values, this is our source data range. The formula below rearranges the values to a single row and then changes their positions randomly.
Dynamic array formula in cell B8:
This formula is useful for randomizing values and resizing their source array. It works only in Excel 365 and spills values to the right as far as needed. A#SPILL error is displayed if the destination cells are not empty.
Explaining formula in cell B8
Tip! You can follow the formula calculations step by step by using the "Evaluate" tool located on the Formula tab on the ribbon. This makes it easier to spot errors and understand the formula in greater detail. The following steps shows the calculations in great detail.
Step 1 - Calculate the number of rows in cell ref
The ROWS function returns the number of rows in a given cell range.
ROWS(array)
ROWS(B2:E4)
returns 3. There are three rows in cell range B2:E4.
Step 2 - Calculate the number of columns in cell ref
The COLUMNS function returns the number of columns in a given cell range.
COLUMNS(array)
COLUMNS(B2:E4)
returns 4. There are four columns in cell range B2:E4.
Step 3 - Calculate the number of cells in cell ref
The asterisk lets you multiply numbers in an Excel formula. This useful now that we want to calculate the total number of cells in B2:E4.
ROWS(B2:E4)*COLUMNS(B2:E4)
becomes
3*4 equals 12.
Step 4 - Create random values
The RANDARRAY function returns a table of random numbers across rows and columns.
RANDARRAY([rows], [columns], [min], [max], [whole_number])
RANDARRAY(, ROWS(B2:E4)*COLUMNS(B2:E4))
becomes
RANDARRAY(, 12)
and returns 12 random decimal values:
{0.464680665246457, 0.768212043461448, ... ,0.281771048521311}
Step 5 - Rearrange values
TOROW(B2:E4)
returns
{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"}.
Step 6 - Sort values in random order
The SORTBY function allows you to sort values from a cell range or array based on a corresponding cell range or array.
SORTBY(array, by_array1, [sort_order1], [by_array2, sort_order2],…)
SORTBY(TOROW(B2:E4), RANDARRAY(, ROWS(B2:E4)*COLUMNS(B2:E4)))
becomes
SORTBY({"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"}, {0.464680665246457, 0.768212043461448, ... ,0.281771048521311})
and returns
{"H", "E", "I", "F", "L", "B", "D", "A", "J", "K", "G", "C"}. Press F9 to recalcualte values, this creates a new random order.
8. Function not working
The TOROW function returns
- #VALUE! error if the second argument [ignore] is invalid.
- #NAME? error if you misspell the function name.
- propagates errors, meaning that if the input contains an error (e.g., #VALUE!, #REF!), the function will return the same error.
8.1 Troubleshooting the error value
When you encounter an error value in a cell a warning symbol appears, displayed in the image above. Press with mouse on it to see a pop-up menu that lets you get more information about the error.
- The first line describes the error if you press with left mouse button on it.
- The second line opens a pane that explains the error in greater detail.
- The third line takes you to the "Evaluate Formula" tool, a dialog box appears allowing you to examine the formula in greater detail.
- This line lets you ignore the error value meaning the warning icon disappears, however, the error is still in the cell.
- The fifth line lets you edit the formula in the Formula bar.
- The sixth line opens the Excel settings so you can adjust the Error Checking Options.
Here are a few of the most common Excel errors you may encounter.
#NULL error - This error occurs most often if you by mistake use a space character in a formula where it shouldn't be. Excel interprets a space character as an intersection operator. If the ranges don't intersect an #NULL error is returned. The #NULL! error occurs when a formula attempts to calculate the intersection of two ranges that do not actually intersect. This can happen when the wrong range operator is used in the formula, or when the intersection operator (represented by a space character) is used between two ranges that do not overlap. To fix this error double check that the ranges referenced in the formula that use the intersection operator actually have cells in common.
#SPILL error - The #SPILL! error occurs only in version Excel 365 and is caused by a dynamic array being to large, meaning there are cells below and/or to the right that are not empty. This prevents the dynamic array formula expanding into new empty cells.
#DIV/0 error - This error happens if you try to divide a number by 0 (zero) or a value that equates to zero which is not possible mathematically.
#VALUE error - The #VALUE error occurs when a formula has a value that is of the wrong data type. Such as text where a number is expected or when dates are evaluated as text.
#REF error - The #REF error happens when a cell reference is invalid. This can happen if a cell is deleted that is referenced by a formula.
#NAME error - The #NAME error happens if you misspelled a function or a named range.
#NUM error - The #NUM error shows up when you try to use invalid numeric values in formulas, like square root of a negative number.
#N/A error - The #N/A error happens when a value is not available for a formula or found in a given cell range, for example in the VLOOKUP or MATCH functions.
#GETTING_DATA error - The #GETTING_DATA error shows while external sources are loading, this can indicate a delay in fetching the data or that the external source is unavailable right now.
7.2 The formula returns an unexpected value
To understand why a formula returns an unexpected value we need to examine the calculations steps in detail. Luckily, Excel has a tool that is really handy in these situations. Here is how to troubleshoot a formula:
- Select the cell containing the formula you want to examine in detail.
- Go to tab “Formulas” on the ribbon.
- Press with left mouse button on "Evaluate Formula" button. A dialog box appears.
The formula appears in a white field inside the dialog box. Underlined expressions are calculations being processed in the next step. The italicized expression is the most recent result. The buttons at the bottom of the dialog box allows you to evaluate the formula in smaller calculations which you control. - Press with left mouse button on the "Evaluate" button located at the bottom of the dialog box to process the underlined expression.
- Repeat pressing the "Evaluate" button until you have seen all calculations step by step. This allows you to examine the formula in greater detail and hopefully find the culprit.
- Press "Close" button to dismiss the dialog box.
There is also another way to debug formulas using the function key F9. F9 is especially useful if you have a feeling that a specific part of the formula is the issue, this makes it faster than the "Evaluate Formula" tool since you don't need to go through all calculations to find the issue.
- Enter Edit mode: Double-press with left mouse button on the cell or press F2 to enter Edit mode for the formula.
- Select part of the formula: Highlight the specific part of the formula you want to evaluate. You can select and evaluate any part of the formula that could work as a standalone formula.
- Press F9: This will calculate and display the result of just that selected portion.
- Evaluate step-by-step: You can select and evaluate different parts of the formula to see intermediate results.
- Check for errors: This allows you to pinpoint which part of a complex formula may be causing an error.
The image above shows cell reference B4:E6 converted to hard-coded value using the F9 key, however, these values cause no errors. The TOROW function requires valid values in the second argument which is not the case in this example.
Tips!
- View actual values: Selecting a cell reference and pressing F9 will show the actual values in those cells.
- Exit safely: Press Esc to exit Edit mode without changing the formula. Don't press Enter, as that would replace the formula part with the calculated value.
- Full recalculation: Pressing F9 outside of Edit mode will recalculate all formulas in the workbook.
Remember to be careful not to accidentally overwrite parts of your formula when using F9. Always exit with Esc rather than Enter to preserve the original formula. However, if you make a mistake overwriting the formula it is not the end of the world. You can “undo” the action by pressing keyboard shortcut keys CTRL + z or pressing the “Undo” button
7.3 Other errors
Floating-point arithmetic may give inaccurate results in Excel - Article
Floating-point errors are usually very small, often beyond the 15th decimal place, and in most cases don't affect calculations significantly.
Useful resources
TOROW function - Microsoft support
Excel TOROW function - Myonlinetraininghub
'TOROW' function examples
The picture above shows data presented in only one column (column B), this happens sometimes when you get an undesired […]
Functions in 'Array manipulation' category
The TOROW function function is one of 11 functions in the 'Array manipulation' category.
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form