# Reversing Integer Values

by Allen Wyatt
(last updated January 10, 2020)

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:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13140) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365.

##### Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

##### MORE FROM ALLEN

Choosing What You See in the Equation Editor

Sometimes it can be helpful to see where non-printing characters are located. Here's how to view non-printing characters ...

Discover More

Changing the User Interface Language

Tired of Windows showing you information in English when you'd much prefer a different language? Here's how to modify the ...

Discover More

The Shift+F4 shortcut is very helpful when you want to repeat an action, such as finding the next occurrence of whatever ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

##### More ExcelTips (ribbon)

Limiting a Calculated Value to a Range

If you want to limit what is returned by a formula to something between lower and upper boundaries, the solution is to ...

Discover More

Determining "Highest Since" or "Lowest Since"

When compiling statistics on a collection of data points, you may want to know whether a particular value is the "highest ...

Discover More

Referencing the Last Six Items in a Formula

If you have a list of data in a column, you may want to determine an average of whatever the last few items are in the ...

Discover More
##### Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 3 - 1?

2019-09-01 07:03:43

Harold Druss

Great tip

2019-07-08 22:18:06

Nur Najwa Nazuan

Hi,
Thank you for the formula,

but i need a reverse with decimal number included.
for example 1 to 7 to reverse 7 to 1,
if the number is 2.6 then it should be 6.4.
How can I do that.

2018-09-02 11:00:44

MIchael Armstrong

@Sherri: =if(A2>0,6-A2,0)

2018-09-01 16:17:39

Sherri

I found the first formula "=6-A2" helpful to reverse scoring on an assessment (i.e., change 4 to 1, 3 to 2, 2 to 3, and 1 to 4), but I also need zero to remain zero (i.e., no reversal). What excel formula could accomplish that?

2014-06-22 14:29:15

Michael (Micky) Avidan

Well..., after a short "Brainstorming" with myself - here is the simplest UDF:
----------------------
Function RVRS(Str)
RVRS = StrReverse(Str)
End Function
-------------
use: =RVRS (A1)
***************
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2014)

2014-06-22 13:56:22

Michael (Micky) Avidan

Sorry, it isn't a Macro - it is a User Defined Function (UDF)
It is very dynamic and is capable to handle any length of Number/String.
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2014)
ISRAEL

2014-06-22 13:08:11

Michael (Micky) Avidan

The Macro can be much simpler and will also reverse any length of Numeric value and/or String.
------------------------------------
Function Reverse_Order(Rng As Range)
If Rng.Count > 1 Then Exit Function
ReDim Arr(Len(Rng))
For D = 1 To Len(Rng)
Arr(D) = Mid(Rng, Len(Rng) - D + 1, 1)
Next
Reverse_Order = Join(Arr, "")
End Function
-------------
so, for a gine value in A1 use: =Reverse_Order(A1)
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2014)
ISRAEL

2014-06-21 20:41:48

Kevin

For the examples given I would use the autofill in reverse order.
My interpretation though was a need to reverse random numbers in this case in column B.
In this situation place 1 - 5 etc in column A, 5 - 1 to column C using autofill. Then place VLOOKUP(C1,\$A\$1:\$B\$5,2,FALSE) in D and copy it down.

2014-06-21 19:44:00

Erik

You could also use Replace (Home ribbon under Find & Select, or <crtl>+f and pick the replace tab).

Start by highlighting all the columns you want to flip, then pick the Replace command.

Because you are flipping 1 & 5 and 2 & 4, you will have to do an intermediate change for each pair (I chose to use 0).
Find = 1, replace with = 0, click "Replace all".
Find = 5, replace with = 1, click "Replace all".
Find = 0, replace with = 5, click "Replace all".
Find = 2, replace with = 0, click "Replace all".
Find = 4, replace with = 2, click "Replace all".
Find = 0, replace with = 4, click "Replace all".

Done!

##### This Site

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.