Written by Allen Wyatt (last updated September 25, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and 2021
Katy has a worksheet that, in some columns, contains integer data values ranging from 1 through 5. (In those particular columns, these are the only values in the column.) She would like to "reverse" these data values, such that 5 becomes 1, 4 becomes 2, 3 stays the same, 2 becomes 4, and 1 becomes 5. She only wants this to happen in certain columns, and she is stuck trying to figure out how to accomplish the task.
There are actually several different ways you can accomplish this task. The first is to use a simple formula to do the reversal. Assume, for instance, that the values you want to reverse are in column A, starting in row 2. The following formula will work:
=6-A2
Copy the formula down as far as you need, and the result is reversed values. You can then copy the values and paste them wherever you want using Paste Special. (You use Paste Special so you can copy just the values, not the formulas that create the values.)
This isn't the only formula you could use, however. You could use the CHOOSE function in this manner:
=CHOOSE(A2,5,4,3,2,1)
Another approach is to set up the numbers 1-5 in a difference set of cells (let's say you put those values in cells T1:T5) and then use the RANK function, in this manner:
=RANK(A2,T1:T5,0) =RANK.EQ(A2,T1:T5,0)
Both return the desired reversal, but the second example (RANK.EQ) should be used in Excel 2010 and later versions because the RANK function was deprecated after Excel 2007.
You could also reverse the values in place by using a macro to do the task. Here's a simple one that will do the job:
Sub ReverseNumbers() Dim rCell As Range For Each rCell In Selection With rCell If IsNumeric(.Value) Then .Value = 6 - .Value End If End With Next End Sub
To use the macro, select the cells you want to reverse and then run it. It first checks to make sure that the cell contains a numeric value; if so, it subtracts the value in the cell from 6, effectively reversing the value.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13140) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and 2021.
Dive Deep into Macros! Make Excel do things you thought were impossible, discover techniques you won't find anywhere else, and create powerful automated reports. Bill Jelen and Tracy Syrstad help you instantly visualize information to make it actionable. You’ll find step-by-step instructions, real-world case studies, and 50 workbooks packed with examples and solutions. Check out Microsoft Excel 2019 VBA and Macros today!
Excel includes the powerful INDIRECT function which can be used to assemble references to other cells in your workbook. ...
Discover MoreWhen you edit a worksheet, adding and deleting rows and columns, Excel automatically updates references to cells ...
Discover MoreGot a large group of people listed in a worksheet and you want to make sure that each person has met with every other ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments