Written by Allen Wyatt (last updated June 6, 2020)
This tip applies to Excel 97, 2000, 2002, and 2003
Many people use Excel as a simple database manager, entering information in different rows of a worksheet. As you are working with your data tables, you may come across a need to reverse the order of the rows in the table. Thus, if you have a table with ten rows, the rows would go from ten to one instead of one to ten.
There is no intrinsic function in Excel that allows you to flip data in this manner. However, you can use the sorting capabilities of Excel to accomplish the same thing by following these general steps:
Figure 1. The Sort dialog box.
If you have to do a lot of data flipping on a daily basis, using the above steps can get rather tiring. In this case, you may want to create a macro to do the job for you. The following macro, FlipRows, will do the trick:
Sub FlipRows() Dim vTop As Variant Dim vEnd As Variant Dim iStart As Integer Dim iEnd As Integer Application.ScreenUpdating = False iStart = 1 iEnd = Selection.Rows.Count Do While iStart < iEnd vTop = Selection.Rows(iStart) vEnd = Selection.Rows(iEnd) Selection.Rows(iEnd) = vTop Selection.Rows(iStart) = vEnd iStart = iStart + 1 iEnd = iEnd - 1 Loop Application.ScreenUpdating = True End Sub
In order to use this macro, all you need to do is select the rows you want flipped and run it. The macro will not change your data, other than flipping the rows. In other words, it will not add any columns of information.
An interesting feature of this approach is that you can quickly adapt it to flipping columns of data. All you need to do is change all occurrences of the word "Rows" to "Columns." Thus, the following becomes the new macro:
Sub FlipColumns() Dim vTop As Variant Dim vEnd As Variant Dim iStart As Integer Dim iEnd As Integer Application.ScreenUpdating = False iStart = 1 iEnd = Selection.Columns.Count Do While iStart < iEnd vTop = Selection.Columns(iStart) vEnd = Selection.Columns(iEnd) Selection.Columns(iEnd) = vTop Selection.Columns(iStart) = vEnd iStart = iStart + 1 iEnd = iEnd - 1 Loop Application.ScreenUpdating = True End Sub
Again, simply select the columns you want to flip and then run the macro.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2653) applies to Microsoft Excel 97, 2000, 2002, and 2003.
Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!
If you want to turn a range of cells by 90 degrees within a worksheet, you need to understand how Excel can handle the ...
Discover MoreIf you need to move down a row and then select that row, you may wonder if there is a shortcut to handle such a ...
Discover MoreWant to easily move information from one cell to another? A quick way to do it is to simply drag and drop using the mouse.
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2020-11-17 11:13:32
Amos
Hi Allen,
Thanks for that, its very useful and time saving solution.
One question though, Is there any way to auto select all data and Flip it, without any input dialog?
2020-06-06 17:26:46
Donald Berg
You should have offered, instead of a newbie inserting and then typing in a new column of numbers (as some might) a simpler method to enter numbers into a new column: Enter 1 into the new column on the top row, then click return, then then rt click and drag the small lower right box in the cell and select "fill series"". Then do the rest to traspose. If you want to transpose from a vertical column to a horizontal one just use the dialogue box (for copy/paste) by selecting rt clicked paste special
Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments