22

Are there any built-in Excel functions that will reverse a string?

1
  • you should pick the answer with strReverse
    – ChatGPT
    Apr 9, 2015 at 16:22

4 Answers 4

9

There is no built-in function that I know of, but you can create your own custom function.

First - create a new module:

  1. Get into VBA (Press Alt+F11)
  2. Insert a new module (Insert > Module)

Second - paste the following function in your new module (Reference):

Function Reverse(Text As String) As String
    Dim i As Integer
    Dim StrNew As String
    Dim strOld As String
    strOld = Trim(Text)
    For i = 1 To Len(strOld)
      StrNew = Mid(strOld, i, 1) & StrNew
    Next i
    Reverse = StrNew
End Function

Now you should be able to use the Reverse function in your spreadsheet

68

The current accepted answer is a poor way to reverse a string, especially when there is one built into VBA, use the following code instead (should act the same but run a LOT faster):

Function Reverse(str As String) As String
    Reverse = StrReverse(Trim(str))
End Function
1
  • 1
    @n00b - "how to create a module" wasn't the question. :) This solution is much more efficient/faster/easier, although I'm not sure why TRIM was added, since extra whitespace wasnt't specified in the question. For "huge" datasets, remove TRIM if you don't need it.
    – ashleedawg
    Oct 28, 2018 at 16:43
4

I found an alternative that doesn't require VBA at https://exceljet.net/formula/reverse-text-string

The formula is

=TEXTJOIN("",1,MID(B5,ABS(ROW(INDIRECT("1:"&LEN(B5)))-(LEN(B5)+1)),1))

where B5 is the input cell.

3
  • 1
    For me, this only returns the last character.
    – hypehuman
    Aug 13, 2020 at 6:41
  • 1
    Works if entered using Ctrl + Shift + Enter
    – ZygD
    Dec 21, 2020 at 19:23
  • Works for me in Office 365. Oct 21, 2021 at 8:43
2

You can use this LET formula:

=LET( string, D6,
       L, LEN( string ),
       CONCAT( MID( string, SEQUENCE( 1, L, L, -1), 1) ) )

It breaks up the string into an array of 1-character cells and then recombines them back into a concatenated string in reverse order.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .