# Flip Data in Excel | Reverse Order of Data in Column/Row

Sometimes, you may have a need to flip the data in Excel, i.e., to reverse the order of the data upside down in a vertical dataset and left to right in a horizontal dataset.

Now, if you’re thinking that there must be an inbuilt feature to do this in Excel, I’m afraid you’d be disappointed.

While there are multiple ways you can flip the data in Excel, there is no inbuilt feature. But you can easily do this using simple a sorting trick, formulas, or VBA.

In this tutorial, I will show you how to flip the data in rows, columns, and tables in Excel.

So let’s get started!

Table of Contents

## Flip Data Using SORT and Helper Column

One of the easiest ways to reverse the order of the data in Excel would be to use a helper column and then use that helper column to sort the data.

### Flip the Data Vertically (Reverse Order Upside Down)

Suppose you have a data set of names in a column as shown below and you want to flip this data:

Below are the steps to flip the data vertically:

- In the adjacent column, enter ‘Helper’ as the heading for the column
- In the helper column, enter a series of numbers (1,2,3, and so on). You can use the methods shown here to do this quickly
- Select the entire data set including the helper column
- Click the Data tab
- Click on the Sort icon
- In the Sort dialog box, select ‘Helper’ in the ‘Sort by’ dropdown
- In the Order drop-down, select ‘Largest to Smallest’
- Click OK

The above steps would sort the data based on the helper column values, which would also lead to reversing the order of the names in the data.

Once done, feel free to delete the helper column.

*In this example, I’ve shown you how to flip the data when you just have one column, but you can also use the same technique if you have an entire table. Just make sure that you select the entire table and then use the helper column to sort the data in descending order.*

### Flip the Data Horizontally

You can also follow the same methodology to flip the data horizontally in Excel.

Excel has an option to sort the data horizontally using the Sort dialog box (the ‘Sort left to right’ feature).

Suppose you have a table as shown below and you want to flip this data horizontally.

Below are the steps to do this:

- In the row below, enter ‘Helper’ as the heading for the row
- In the helper row, enter a series of numbers (1,2,3, and so on).
- Select the entire data set including the helper row
- Click the Data tab
- Click on the Sort icon
- In the Sort dialog box, click on the Options button.
- In the dialog box that opens, click on ‘Sort left to right’
- Click OK
- In the Sort by drop-down, select Row 3 (or whatever row has your helper column)
- In the Order drop-down, select ‘Largest to Smallest’
- Click OK

The above steps would flip the entire table horizontally.

Once done, you can remove the helper row.

## Flip Data Using Formulas

Microsoft 365 has got some new formulas that make it really easy to reverse the order of a column or a table in Excel.

In this section, I’ll show you how to do this using the SORTBY formula (if you’re using Microsoft 365), or the INDEX formula (if you’re not using Microsoft 365)

### Using the SORTBY function (available in Microsoft 365)

Suppose you have a table as shown below and you want to flip the data in this table:

To do this, first, copy the headers and place them where you would want the flipped table

Now, use the following formula below the cell in the left-most header:

=SORTBY($A$2:$B$12,ROW(A2:A12),-1)

The above formula sorts the data and by using the result of the ROW function as the basis to sort it.

The ROW function in this case would return an array of numbers that represents the row numbers in between the specified range (which in this example would be a series of numbers such as 2, 3, 4, and so on).

And since the third argument of this formula is -1, it would force the formula to sort the data in descending order.

The record that has the highest row number would come at the top and the one which has the lowest rule number would go at the bottom, essentially reversing the order of the data.

Once done, you can convert the formula to values to get a static table.

### Using the INDEX Function

In case you don’t have access to the SORTBY function, worry not – you can use the amazing INDEX function.

Suppose you have a dataset of names as shown below and you want to flip this data.

Below is the formula to do this:

=INDEX($A$2:$A$12,ROWS(A2:$A$12))

** How does this formula work?**

The above formula uses the INDEX function that would return the value from the cell based on the number specified in the second argument.

The real magic happens in the second argument where I have used the ROWS function.

Since I have locked the second part of the reference in the ROWS function, in the first cell, it would return the number of rows between A2 and A12, which would be 11.

But when it goes down the rows, the first reference would change to A3, and then A4, and so on, while the second reference would remain as is because I have locked it and made it absolute.

As we go down the rows, the result of the ROWS function would decrease by 1, from 11 to 10 to 9, and so on.

And since the INDEX function returns us the value based on the number in the second argument, this would ultimately give us the data in the reverse order.

You can use the same formula even if you have multiple columns in the data set. however, you will have to specify a second argument that would specify the column number from which the data needs to be fetched.

Suppose you have a data set as shown below and you want to reverse the order of the entire table:

Below is the formula that will do that for you:

=INDEX($A$2:$B$12,ROWS(A2:$A$12),COLUMNS($A$2:A2))

This is a similar formula where I’ve also added a third argument that specifies the column number from which the value should be fetched.

To make this formula dynamic, I have used the COLUMNS function that would keep on changing the column value from 1 to 2 to 3 as you copy it to the right.

Once done, you can convert the formulas to values to make sure that you have a static result.

## Flip Data Using VBA

If flipping the data in Excel is something you have to do quite often, you can also try the VBA method.

With a VBA macro code, you can copy and paste it once within the workbook in the VBA editor, and then reuse it over and over again in the same workbook.

You can also save the code in the Personal Macro Workbook or as an Excel add-in and be able to use it in any workbook on your system.

Below is the VBA code that would flip the selected data vertically in the worksheet.

Sub FlipVerically() 'Code by Sumit Bansal from TrumpExcel.com Dim TopRow As Variant Dim LastRow As Variant Dim StartNum As Integer Dim EndNum As Integer Application.ScreenUpdating = False StartNum = 1 EndNum = Selection.Rows.Count Do While StartNum < EndNum TopRow = Selection.Rows(StartNum) LastRow = Selection.Rows(EndNum) Selection.Rows(EndNum) = TopRow Selection.Rows(StartNum) = LastRow StartNum = StartNum + 1 EndNum = EndNum - 1 Loop Application.ScreenUpdating = True End Sub

To use this code, you first need to make the selection of the data set that you want to reverse (excluding the headers), and then run this code.

**How does this code work?**

The above code first counts the total number of rows in the data set and assigns that to the variable EndNum.

It then uses the Do While loop where the sorting of the data happens.

The way it sorts this data is by taking the first and the last row and swapping these. It then moves to the 2nd row in the second last row and then swaps these. Then it moves to the third row in the third last row and so on.

The loop ends when all the sorting is done.

It also uses the Application.ScreenUpdating property and sets it to FALSE while running the code, and then turn it back to TRUE when the code has completed running.

This ensures that you don’t see the changes happening in real-time on your screen it also speeds up the process.

**How to use the Code?**

Follow the below steps to copy and paste this code in the VB Editor:

- Open the Excel file where you want to add the VBA code
- Hold the ALT key and press the F-11 key (you can also go to the Developer tab and click on the Visual Basic icon)
- In the Visual Basic Editor that opens up, there would be a Project Explorer on the left part of the VBA editor. If you don’t see it, click on the ‘View’ tab and then click on ‘Project Explorer’
- Right-click on any of the objects for the workbook in which you want to add the code
- Go to the Insert option and then click on Module. This will add a new module to the workbook
- Double-click on the module icon in the Project Explorer. This will open the code window for that module
- Copy and paste the above VBA code into the code window

To run the VBA macro code, first select the dataset that you want to flip (excluding the headers).

With the data selected, go to the VB Editor and click on the green play button in the toolbar, or select any line in the code and then hit the F5 key

So these are some of the methods you can use to flip the data in Excel (i.e., reverse the order of the data set).

All the methods that I have covered in this tutorial (formulas, SORT feature, and VBA), can be used to flip the data vertically and horizontally (you’ll have to adjust the formula and VBA code accordingly for horizontal data flipping).

I hope you found this tutorial useful.

**Other Excel tutorials you may also like:**