How-to recipes · Analysis

How to reverse a list in Excel

Flip the order of a column or row with SORTBY and SEQUENCE or CHOOSEROWS in Microsoft 365, INDEX and ROWS in older Excel, or a helper column and Sort.

Beginner SORTBY SEQUENCE ROWS CHOOSEROWS INDEX TOROW COLUMNS

Data often arrives in the wrong order for what you need: a bank export lists the newest transaction first but your running balance needs the oldest first; a log has the latest entry at the bottom but the dashboard should show it at the top. If there is a date or number column, you can simply sort by it. But when the order is the information, with no column to sort by, you need to reverse the list exactly as it is. Excel has no reverse button, but there are several easy ways.

The example data

Five months in A2:A6. The goal is May, Apr, Mar, Feb, Jan.

Microsoft 365: SORTBY with SEQUENCE

SEQUENCE numbers the rows 1 to 5, and SORTBY sorts the list by those numbers in descending order:

C2fx=SORTBY(A2:A6,SEQUENCE(ROWS(A2:A6)),-1)
ABC
1Month
2JanMay
3FebApr
4MarMar
5AprFeb
6MayJan

ROWS(A2:A6) is 5, SEQUENCE gives 1 to 5, and sorting by it in descending order reverses the list.

The formula adapts to any length because ROWS counts the rows. It also works on several columns at once: =SORTBY(A2:C6,SEQUENCE(ROWS(A2:C6)),-1) reverses whole records while keeping each row together.

Alternative: CHOOSEROWS

CHOOSEROWS returns rows in any order you list. A sequence that counts down from the last row reverses the list:

Formula
=CHOOSEROWS(A2:A6,SEQUENCE(ROWS(A2:A6),,ROWS(A2:A6),-1))

SEQUENCE(5,,5,-1) produces 5, 4, 3, 2, 1: five rows, starting at 5, stepping by -1. Both formulas give the same result; SORTBY is a little shorter.

Excel 2016 and 2019: INDEX with a shrinking ROWS

In B2 type this formula and copy it down to B6:

B2fx=INDEX($A$2:$A$6,ROWS(A2:$A$6))
AB
1MonthReversed
2JanMay
3Feb
4Mar
5Apr
6May

In B2, ROWS(A2:$A$6) is 5, so INDEX returns the 5th month. Copied down, the range shrinks to 4, 3, 2, 1 rows.

Result: May

  1. ROWS(A2:$A$6) counts the rows from the current position to the fixed end. In B2 that is 5.
  2. When the formula is copied to B3, the unlocked start moves to A3 and ROWS becomes 4.
  3. INDEX returns the item at that position, so each row picks the item one step closer to the top.

The dollar signs matter: the end of the range $A$6 is locked and the start A2 is not. Copying past row 6 returns an error, which tells you the list has ended. Cell references: relative, absolute and mixed explains mixed references.

Without formulas: helper column + Sort

  1. Insert a helper column next to the data and fill it with 1, 2, 3 ... (type 1 and 2, select both and double-click the fill handle).
  2. Select the data including the helper column.
  3. Data > Sort, sort by the helper column, Largest to Smallest.
  4. Delete the helper column.

This changes the data in place, works in every version, and is the best choice for a one-off flip of a large table.

Reversing a row

For data laid out across columns, the logic is the same with columns: in Microsoft 365, =SORTBY(B1:F1,SEQUENCE(1,COLUMNS(B1:F1)),-1) reverses the row. To turn a reversed column into a row in one go, wrap the result in TOROW. In older versions, use =INDEX($B$1:$F$1,COLUMNS(B1:$F$1)) and copy it to the right.

Pitfalls

  • Blank cells in the source are returned as 0 by INDEX and SORTBY. Wrap the formula in IF(...="","",...) or filter blanks out first.
  • Formulas in the source that refer to neighbouring rows (such as running totals) do not move with the reversed copy; the copy contains values, not formulas.
  • Sorting by a date column is safer when there is one. Reversing assumes the current order is exactly the opposite of what you want, which is not true if a single row was inserted out of place.
  • Spill space. The Microsoft 365 formulas need empty cells for the whole result, otherwise you see #SPILL!.
Tip. Reversing is often a step before a running total or a chart. See How to calculate a running total in Excel and Sorting and filtering data. The dynamic array functions used here are explained in Dynamic arrays: spill, FILTER, SORT, UNIQUE, SEQUENCE and #.
⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 14 KB

More how-to recipes