Reverse a string

BrianM

Well-known Member
Joined
Jan 15, 2003
Messages
768
Office Version
  1. 2016
Platform
  1. Windows
Is there a function that can reverse the contents of a cell?

i.e. A1=Cat ...result = tac

Thanks,
Brian
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Or a User Defined function

Code:
Function reverse(S As String)
    Dim Temp As String, I As Integer, n As Integer
    n = Len(S)
    For I = n To 1 Step -1
        Temp = Temp & Mid(S, I, 1)
    Next I
    reverse = Temp & Right(S, Len(S) - n)
End Function

ASAP-Utilities is better though unless you are going to be doing this a lot.
 
Upvote 0
Hi,

there is an inbuiltfunction
might be a more recent one
Code:
MsgBox StrReverse("cat")
kind regards,
Erik
 
Upvote 0
Good evening BrianM

This would do the trick :

Code:
Function Reverse(Backwards As String)
Dim Length, Pos As Integer
Reverse = ""
Length = Len(Backwards)
For Pos = Length To 1 Step -1
Reverse = Reverse & Mid(Backwards, Pos, 1)
Next Pos
End Function

My add-in, available from the link below has this as a function, so once installed =REVERSE(A1) would show tac (if A1 contained "cat")

HTH

DominicB
 
Upvote 0
talking about functions:
Code:
Function reverse(S As String)
    reverse = StrReverse(S)
End Function
so no need to loop
as mentioned, check if it works for your version
 
Upvote 0
Using formulas, (not too pretty though):-
Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABAC
1ToddBardoniinodraB ddoTTTTTTTTTTTTTTTinodraBddoT
Sheet1

In C1:AB1
Code:
=LEFT(RIGHT(Sheet1!$A$1,COLUMN(1:$256)),1)
Confirmed w/ Ctrl+Shift+Enter

In AC1
Code:
=LEFT(C1&D1&E1&F1&G1&H1&I1&J1&K1&L1&M1&N1&O1&P1&Q1&R1&S1&T1&U1&V1&W1&X1&Y1&Z1&AA1&AB1,LEN($A$1))
 
Upvote 0
Hi Erik

That "StrReverse" commands a handy thing to know. It would be interesting to know when it was introduced. As far back as XL2000...?

DominicB
 
Upvote 0
Domonic,

I'll check it out on an elder PC with XL2000.
Almost sure it wasn't available in XL97

best regards,
Erik
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,013
Members
448,935
Latest member
ijat

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top