Any Excel function that will reverse a string?

16

5

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

mindless.panda

Posted 2010-03-19T02:43:54.257

Reputation: 6 642

you should pick the answer with strReverse – Max Hodges – 2015-04-09T16:22:34.403

Answers

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

quickcel

Posted 2010-03-19T02:43:54.257

Reputation: 4 203

63

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

Grant Peters

Posted 2010-03-19T02:43:54.257

Reputation: 731

@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 – 2018-10-28T16:43:33.430