How to Use Excel SORT Formula for Sorting Rows and Columns
Question details
The user needs to sort horizontal rows and two-dimensional ranges using the Excel SORT function, as the standard formula syntax only sorts vertical columns correctly.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- The user entered horizontal data across multiple rows and attempted to sort each row numerically using standard SORT formulas, but the data remained unchanged.
- Observed behavior
- The SORT function sorts columns correctly but leaves horizontal row values in their original order because the formula is missing the specific parameter to sort by column.
Ensure you are using a version of Excel that supports dynamic array functions (such as Microsoft 365, Excel 2021, or Excel for the web), as the SORT, TOCOL, and WRAPROWS functions are unavailable in older standalone versions.
Sort Horizontal Rows Using the by_col Parameter
Adjust the SORT function's syntax to include the fourth argument, forcing Excel to sort across columns horizontally.
By default, the Excel SORT function sorts data vertically (by row). To sort data horizontally (across columns), you must explicitly set the [by_col] argument to TRUE.
Click on an empty cell where you want the sorted horizontal row to begin spilling its results.
Type the formula =SORT(A1:E1,,,TRUE), ensuring you replace A1:E1 with your actual horizontal data range.
Press Enter. The numbers or text will now sort horizontally in ascending order across the adjacent cells.

Sort and Reshape a Two-Dimensional Range
Combine SORT, TOCOL, and WRAPROWS functions to sort all values across a multi-row and multi-column dataset.
Correct Google Sheets Syntax in Excel
Fix open-ended reference errors caused by pasting Google Sheets formulas directly into Microsoft Excel.
Easily Sort Rows and Columns with WPS Office
WPS Spreadsheet offers powerful dynamic array functions to help you sort, filter, and reshape your data instantly. Experience seamless formula handling and an intuitive interface that makes organizing complex data effortless.
- 1. Download and install: Download WPS Office for free from the official website and install it on your device.
- 2. Open your workbook: Launch WPS Spreadsheet and open your existing data file.
- 3. Enter the formula: Click on an empty cell and enter the =SORT() or =WRAPROWS() formula tailored to your data range.
- 4. Apply dynamic arrays: Press Enter to see the dynamic array automatically spill your beautifully sorted rows and columns.

Frequently Asked Questions
Why does my SORT formula leave horizontal rows unchanged?
The SORT function defaults to sorting data vertically (by row). To sort data horizontally (by column), you must provide the fourth argument in the formula, [by_col], and set it to TRUE. For example: =SORT(A1:E1,,,TRUE).
Can I sort a row from largest to smallest using a formula?
Yes. You can dictate the sort order using the third argument, [sort_order]. Set this argument to -1 for descending order. A complete formula for a horizontal row would be =SORT(A1:E1, 1, -1, TRUE).
Why does =SORT(A3:FR) return an error in Excel?
Open-ended range references like A3:FR are standard in Google Sheets but are invalid syntax in Microsoft Excel. To fix the error, you must specify the exact ending row, such as A3:FR100.
What does the TOCOL function do in the sorting formula?
TOCOL takes a two-dimensional range or array and transforms it into a single vertical column. This allows the SORT function to easily sort all values in a grid numerically before they are re-wrapped into a table using WRAPROWS.




