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

Specifying the Size of Chart Objects

Unhappy with the default size that Excel uses for embedded chart objects? You can't change the size at which they are ...

Discover More

Sorting Data Containing Merged Cells

When formatting the layout of your worksheet, Excel allows you to easily merge adjacent cells together. This can cause havoc ...

Discover More

Nifty Zooming with the Mouse

Want to use the mouse to control the zoom level for your document? You can do it by combining your mouse use with the Ctrl ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (ribbon)

Copying Worksheets in a Macro

Copying worksheets (one or many) is easy to do manually. What is not well known is that it is even easy to make the copies in ...

Discover More

Self-Deleting Macros

Macros are very powerful, but you may not want them to always be available to a user. Here are some ways you can limit their ...

Discover More

Bypassing the BeforeClose Event

Hold down the Shift key as you open a workbook, and Excel bypasses any "startup macros" that may be in the workbook. If you ...

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. 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 + 4?

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.