Function Problems

How to Sort Excel Values Horizontally in Each Row Without VBA

Maira MehtabMaira Mehtab Oct 26, 2026 868 views

Question details

Sort values in columns horizontally from lowest to highest, independently for each row, without using VBA.

How to Sort Excel Values Horizontally in Each Row
Product
Excel
Device & OS
not provided
Scenario
Organizing row-level data where each part number has varying numbers of assigned locations that need to be arranged in ascending order horizontally.
Observed behavior
The values are scattered unsorted across multiple columns in each row, and a formula or Power Query solution is needed to sort them left to right automatically.
Before you start

Ensure you are using a modern spreadsheet version (like Microsoft 365, Excel 2021, or the latest WPS Office) to access dynamic array functions like SORT, LET, and FILTER.

Solution 1Recommended

Use Dynamic Array Formulas (SORT and LET)

This is the most efficient method for Microsoft 365 and modern Excel users, utilizing dynamic array formulas to sort each row independently while ignoring blank cells.

By combining the SORT, FILTER, and LET functions, you can create a single formula that evaluates the horizontal range of a specific row, removes any empty cells, and spills the sorted values into adjacent columns.

1
Select the destination cell

Click on the first cell in a blank column adjacent to your dataset (e.g., column J, assuming your data ends at column H).

2
Enter the SORT formula

Type the formula: =LET(data, B1:INDEX(H1:H1, COUNTA(B1:H1)), SORT(FILTER(data, data<>""),,,TRUE))

3
Apply the formula

Press Enter. The sorted values will automatically spill horizontally into the neighboring columns for that row.

4
Copy the formula down

Click the bottom-right corner of the cell containing the formula and drag the fill handle down to apply it to all the remaining rows in your dataset.

Use Dynamic Array Formulas (SORT and LET)
Formula Breakdown: The TRUE argument at the end of the SORT function specifically tells the spreadsheet to sort the array horizontally (by columns) instead of vertically (by rows).
Easy Spreadsheet Solution

Sort Rows Horizontally with WPS Spreadsheets

WPS Office provides built-in support for horizontal sorting. You can easily sort data left-to-right using the intuitive Custom Sort menu, or take advantage of modern dynamic array functions like SORT to handle large datasets effortlessly.

  1. 1. Open your file in WPS Office: Launch WPS Spreadsheets and open your target workbook.
  2. 2. Access the Sort menu: Highlight the row data you want to sort. Navigate to the Data tab and click 'Sort'.
  3. 3. Choose left-to-right sorting: Click the 'Options' button in the Sort dialog box, check 'Sort left to right', and click OK.
  4. 4. Use dynamic arrays for bulk tasks: For multiple rows, simply type =SORT(B1:H1, 1, 1, TRUE) in an empty adjacent column and drag it down.
100% format compatibility with Microsoft Excel (.xlsx)Native support for dynamic array formulas like SORT and FILTERBuilt-in 'Sort left to right' options in the standard Sort dialogFree, lightweight, and fast alternative to heavy office suites
microsoft office alternative - wps office

Frequently Asked Questions

Can I sort data left to right using the standard Excel Sort menu?

Yes. Select your data, go to Data > Sort, click on 'Options', and select 'Sort left to right'. However, doing this manually requires you to sort one continuous block or row at a time, which can be tedious for hundreds of independent rows.

Why is the SORT formula returning a #NAME? error?

The #NAME? error occurs if your spreadsheet software does not support dynamic array functions. The SORT function is only available in Microsoft 365, Excel 2021, Excel for the Web, and modern alternatives like WPS Office.

Does Power Query permanently alter my original data?

No. Power Query establishes a connection to your source data, applies your sorting and unpivoting steps in the background, and loads the transformed result into a completely new table, leaving your original data untouched.

How do I ignore blank cells when sorting rows horizontally?

You can wrap your data range in the FILTER function to exclude blanks before passing it to the SORT function. For example: =SORT(FILTER(B1:H1, B1:H1<>""), 1, 1, TRUE).