# Reverse a string

#### BrianM

##### Well-known Member
Is there a function that can reverse the contents of a cell?

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

Thanks,
Brian

### Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Is there a function that can reverse the contents of a cell?

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

Thanks,
Brian

ASAP Utilities has a function that does just that,

www.asap-utilities.com

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.

Thanks to you both.

Hi,

there is an inbuiltfunction
might be a more recent one
Code:
``MsgBox StrReverse("cat")``
kind regards,
Erik

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

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

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))``

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

Domonic,

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

best regards,
Erik

Replies
3
Views
304
Replies
5
Views
231
Replies
3
Views
302
Replies
4
Views
173
Replies
1
Views
205

1,216,496
Messages
6,130,983
Members
449,611
Latest member
Bushra

### 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.

### Which adblocker are you using?

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

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