logo
search
Function Problems

How to Use Excel SORT Formula for Sorting Rows and Columns

Steve KSteve K Sep 28, 2026 869 views

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.

How to Use the Excel SORT Formula for Sorting Rows and Columns
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.
Before you start

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.

Solution 1Recommended

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.

1
Select the target cell

Click on an empty cell where you want the sorted horizontal row to begin spilling its results.

2
Enter the SORT formula

Type the formula =SORT(A1:E1,,,TRUE), ensuring you replace A1:E1 with your actual horizontal data range.

3
Apply the function

Press Enter. The numbers or text will now sort horizontally in ascending order across the adjacent cells.

Sort Horizontal Rows Using the by_col Parameter
Sort in Descending Order: To sort the row from largest to smallest, modify the third argument ([sort_order]) to -1. Your formula should look like this: =SORT(A1:E1,,-1,TRUE).
Advanced Spreadsheets

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. 1. Download and install: Download WPS Office for free from the official website and install it on your device.
  2. 2. Open your workbook: Launch WPS Spreadsheet and open your existing data file.
  3. 3. Enter the formula: Click on an empty cell and enter the =SORT() or =WRAPROWS() formula tailored to your data range.
  4. 4. Apply dynamic arrays: Press Enter to see the dynamic array automatically spill your beautifully sorted rows and columns.
Seamless compatibility with Microsoft Excel formulas and .xlsx formats.Full support for advanced dynamic array functions like SORT, FILTER, and UNIQUE.Lightweight, fast installation with a user-friendly ribbon interface.Completely free to download and use for your everyday productivity needs.
microsoft office alternative - wps office

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.