Macro to Reverse Text in Excel

Excel has no function to reverse text. This short VBA function adds one, and two macros reverse the characters or the word order in the selected cells.

Works inExcel 2010 and later, Windows and Mac
UndoNot possible. Save a copy first
Save asMacro-Enabled Workbook (.xlsm)

New to macros? See how to use the macros on this site: copy the code, paste it into a module with Alt + F11, and run it with Alt + F8.

A REVERSETEXT function

Paste this into a module, then use =REVERSETEXT(A2):

Function REVERSETEXT(txt As String) As String
    REVERSETEXT = StrReverse(txt)
End Function

=REVERSETEXT("Excel") returns lecxE.

Reverse the selected cells

Sub ReverseSelection()
    Dim c As Range
    For Each c In Selection
        If Not c.HasFormula And VarType(c.Value) = vbString Then
            c.Value = StrReverse(c.Value)
        End If
    Next c
End Sub

Reverse the word order

Turns Anand Ajay into Ajay Anand, for example:

Function REVERSEWORDS(txt As String) As String
    Dim w, i As Long
    w = Split(Trim(txt), " ")
    For i = UBound(w) To 0 Step -1
        REVERSEWORDS = REVERSEWORDS & " " & w(i)
    Next i
    REVERSEWORDS = Trim(REVERSEWORDS)
End Function

Use it as =REVERSEWORDS(A2).

Without a macro (Excel 365)

A formula can reverse text using MID, SEQUENCE and CONCAT:

To Formula
Reverse characters =CONCAT(MID(A2,SEQUENCE(LEN(A2),,LEN(A2),-1),1))
Reverse words =TEXTJOIN(" ",,SORTBY(TEXTSPLIT(A2," "),SEQUENCE(,COUNTA(TEXTSPLIT(A2," "))),-1))

Things to know

  • Custom functions only work in a macro-enabled workbook (.xlsm), or when saved in an add-in.
  • Numbers stored as numbers are skipped by the macro. Format them as text first if you need them reversed.

Related macros