Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Reversing Cell Contents.

Reversing Cell Contents

by Allen Wyatt
(last updated August 9, 2016)

4

Did you ever want to reverse the contents of what is contained in a cell? Using the Reverse macro, you can easily change "My text" to "txet yM." The macro is instructive in techniques to access and modify the contents of a cell.

Sub Reverse()
    If Not ActiveCell.HasFormula Then
        sRaw = ActiveCell.Text
        sNew = ""
        For J = 1 To Len(sRaw)
            sNew = Mid(sRaw, J, 1) + sNew
        Next J
        ActiveCell.Value = sNew
    End If
End Sub

This macro only affects a single selected cell, and it will not make any changes to a cell that contains a formula.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3451) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Reversing Cell Contents.

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

AutoCorrecting for Your Common Errors

AutoCorrect is a great way to correct your spelling, particularly if you misspell the same words over and over. Here's a ...

Discover More

Comment Dates Updated Inappropriately

Using the comment capabilities of Word is a common occurrence when developing a document. What do you do, however, if the ...

Discover More

Removing All Macros

Macros are stored as part of a workbook so that they are always available when you have the workbook open. If you want to get ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (ribbon)

Determining If a Number is Odd or Even

If you need to know whether a particular value is odd or even, you can use this simple formula. Designed to be used in a ...

Discover More

Summing Only Visible Values

When you use SUM to determine the total of a range of values, Excel doesn't really pay attention to whether the values are ...

Discover More

Skipping Hidden Rows in a Macro

As your macro processes information in a worksheet, you may want to make sure that it skips over rows that are hidden. The ...

Discover More
Subscribe

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

View most recent newsletter.

Comments

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 2 + 1?

2016-08-12 11:15:09

JMJ

@Micky,
OK, well played! :-)


2016-08-10 06:33:02

Michael (Micky) Avidan

@JMJ,
It will still remain a single VBA command:

If Not ActiveCell.HasFormula Then Selection = StrReverse(Selection)

--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2017)
ISRAEL


2016-08-09 07:45:53

JMJ

@Micky
Yes, very nice!
But there IS a difference: Allen's macro explicitly excludes formulas, while yours doesn't.
So, a cell containing A1 & A2 will be ignored in the first case and its content will be reverted in the second. But the formula is gone, then!
Using one solution or the other depends on what you really need...
JMJ


2016-08-09 07:22:22

Michael (Micky) Avidan

To the best of my knowledge - the following single command will achieve the same:

Selection = StrReverse(Selection)

--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2017)
ISRAEL


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.

Newest Tips
Subscribe

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

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.