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

Restoring a Deleted File

Delete a file in Drive and it is moved to the Trash folder. You can recover files previously deleted so they can be used once ...

Discover More

Odd Arrow Key Behavior

Press the up or down arrow keys, and you expect Excel to change which cell is selected. If this doesn't occur on your ...

Discover More

Appending to a Non-Excel Text File

Does your macro need to add information to the end of a text file? This is called appending, and is done using the technique ...

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)

Recording a Macro

One of the most common ways of creating macros is to use Excel's macro recorder. This tip shows how easy it is to use the ...

Discover More

Disabling Shift Key Use when Opening a Workbook

Open up a workbook, and Excel normally runs the macros associated with that workbook. You can disable the automatic running ...

Discover More

Converting Text to Numbers

Import information from a program external to Excel, and your numbers may be treated as text because of the way that 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 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 seven minus 6?

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


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
Share