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

Fatal Errors in Word

If Word runs into a problem and the program can't continue, that can be distressing. Here are some things you can check to ...

Discover More

Moving and Copying Cells

At the very heart of editing is the ability to move and copy cells in a worksheet. Understanding the differences between ...

Discover More

Automatically Printing a Range

If you want to automatically print a particular area of your worksheet at a specific time of day, you'll love this tip. With ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

MORE EXCELTIPS (RIBBON)

Counting the Times a Worksheet is Used

Do you need to know how many times a worksheet has been used? Excel doesn't track that information, but you can develop some ...

Discover More

Replacing Some Formulas with the Formula Results

Macros are often used to process the data stored in a worksheet. Some of these processing needs can be pretty specific to ...

Discover More

Transferring Data between Worksheets Using a Macro

Macros can be used for all sorts of data processing needs. One need that is fairly common is the need to move data from one ...

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 for this tip:

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. 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 9 - 7?

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.

Links and Sharing