Written by Allen Wyatt (last updated January 27, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365
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:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3451) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Reversing Cell Contents.
Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!
If you have a text string that contains both letters and numbers and you want to convert those letters to numbers ...
Discover MoreYou can create macros that run whenever Excel detects a certain event happening within an entire workbook. This tip ...
Discover MoreYou can, within a macro, save a workbook in several different file formats that are understood by Excel. However, you may ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments