Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. 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

Written by Allen Wyatt (last updated January 27, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


1

Did you ever want to reverse the contents of what is contained in a cell? Using the StrReverse function in VBA, you can easily change "My text" to "txet yM."

Dim sTemp As String

sTemp = "My text"
sTemp = StrReverse(sTemp)

When completed, the text in the sTemp variable will be equal to "txet yM." If you want to reverse the contents of a cell in a worksheet, you could use the following:

Selection = StrReverse(Selection)

This reverses whatever cell is selected in the worksheet. I find it helpful, though, to build out the usage just a bit to make sure that only a single cell is selected and that the cell does not contain a formula:

If Selection.Count =1 Then
    If Not Selection.HasFormula Then Selection = StrReverse(Selection)
End If

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

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 (3451) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. 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

Using Macros in Protected Workbooks

Having problems with using macros in a protected workbook? There could be any number of causes (and solutions) as ...

Discover More

Extracting Targeted Records from a List

If you have a bunch of data in an Excel worksheet, you may need to work with just a subset of that data. One way to do ...

Discover More

Workbook Loses All Conditional Formatting

Workbooks created in very old versions of Excel can, at times, have issues when opened in later versions of the program. ...

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)

Storing Macros in Templates

How Excel uses templates is different than how Word uses templates. This tip looks at those differences and discusses ...

Discover More

Showing RGB Colors in a Cell

Excel allows you to specify the RGB (red, green, and blue) value for any color used in a cell. Here's a quick way to see ...

Discover More

Creating a Floating Macro Button

Macros can make your use of Excel much more powerful. If you have a macro that is triggered by an on-screen button, 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}] (all 7 characters, in the sequence shown) 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 8 - 5?

2024-01-28 14:10:59

J. Woolley

My Excel Toolbox includes the following function to reverse the value(s) of a constant or a cell or a range of cells and return the result(s) as text:
=Reverse(Value)
For example, Abc becomes cbA and 123 becomes 321 and -1.23 becomes 32.1- and TRUE becomes eurT. Value might also be the result of a function like PI(). If Value is an error like NA() it is not reversed.
If Value is an array or a range of cells, an array is returned. For example:
=Reverse({"Hello","There"})
returns a row vector with olleH and erehT in adjacent columns.
If Value is a non-contiguous range of cells, only its first contiguous Area applies. For example:
=Reverse((A1:C5,E1:E9))
returns an array with 5 rows and 3 columns.
When using pre-2021 versions of Excel without support for dynamic arrays, review the PDF file UseSpillArray.pdf.
See https://sites.google.com/view/MyExcelToolbox


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.