Sort Each Row Individually in Excel Using a LAMBDA Formula

Sorting rows in Excel typically refers to rearranging entire datasets based on values in a specific column or row. But what if you want to sort each row individually in Excel, from left to right? While Excel doesn’t offer a built-in feature for this, the power of LAMBDA functions and dynamic arrays makes it possible to perform this operation with a single formula.

In this tutorial, you’ll learn how to sort each row individually in Excel—whether in ascending or descending order—using a flexible LAMBDA-based formula. This technique is especially useful when dealing with row-wise scores, timelines, or customized data transformations, and it requires no helper columns or manual sorting.

Formula to Sort Each Row Individually in Excel

=LET(
   range, array, 
   DROP(
      REDUCE("", SEQUENCE(ROWS(range)), LAMBDA(acc, seq, VSTACK(acc, SORT(CHOOSEROWS(range, seq), 1, -1, TRUE)))), 1
   )
)

Replace array with your actual data range.

Example Dataset

Here’s a real-life dataset where sorting each row individually in Excel can be helpful—for example, analyzing monthly production figures for different fruits, highlighting each fruit’s production from highest to lowest:

ProductJanFebMarAprMay
Apple12095130110125
Mango8510510011590
Blue Berry140135120125150

The following formula sorts each product’s monthly production values in descending order:

=LET(
   range, B2:F4, 
   DROP(
      REDUCE("", SEQUENCE(ROWS(range)), LAMBDA(acc, seq, VSTACK(acc, SORT(CHOOSEROWS(range, seq), 1, -1, TRUE)))), 1
   )
)

To include product names in the result, use the HSTACK function:

=HSTACK(A2:A4, <above_formula>)
Example showing how to sort each row individually in Excel using a LAMBDA formula

Formula Explanation

  • SORT(CHOOSEROWS(range, seq), 1, -1, TRUE) sorts one row (specified by seq) from left to right in descending order.
    • CHOOSEROWS(range, seq) extracts the seq-th row from the data range.
  • VSTACK(acc, ...) appends the sorted row vertically to the result accumulator.
  • REDUCE("", SEQUENCE(ROWS(range)), LAMBDA(acc, seq, ...)) iterates through each row index and builds the final sorted array.
  • DROP(..., 1) removes the initial empty element introduced by REDUCE.

This approach lets you sort each row individually in Excel without manual intervention.

Frequently Asked Questions

Can I sort rows horizontally in Excel using a formula?
Yes. While Excel doesn’t have a built-in command for this, you can use a combination of LAMBDA, SORT, and dynamic array functions to sort each row individually from left to right. For a single row, the SORT function with its last argument set to TRUE can sort across columns. (Syntax: SORT(array, [sort_index], [sort_order], [by_col]))

Which Excel versions support sorting each row with this formula?
This method requires Excel 365 or Excel 2021+, which support LAMBDA, SORT, REDUCE, SEQUENCE, and other dynamic array functions.

Can I sort each row in ascending order instead?
Yes. Change the sort_order from -1 to 1 in the formula to sort from lowest to highest.

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Sort by Field Labels Using the SORT and XMATCH Combo in Excel

Want to sort your Excel data by column names instead of column positions? Learn...

How to Sort Pie Slices in Google Sheets

To sort pie slices in a pie chart, you need to sort the data...

Filter Items Unique to Groups in Google Sheets

In this tutorial, we'll learn how to filter items unique to groups in Google...

Find Common Items Across Multiple Columns in Google Sheets

This tutorial explains how to find common items across multiple columns in Google Sheets....

More like this

Sort by Field Labels Using the SORT and XMATCH Combo in Excel

Want to sort your Excel data by column names instead of column positions? Learn...

Dynamic Way to Insert Blank Rows in a Table in Excel

Do you want to easily insert n number of blank rows in a table...

Insert N Empty Cells Between Values in Excel (Dynamic Array)

Do you want to space out data by inserting a specific number of empty...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.