Reverse numbers and text

uttamsaxena

Board Regular
Joined
Apr 22, 2003
Messages
179
How can I reverse ------

1) A number e.g. 12345 to 54321

2) A word e.g uttamsaxena to anexasmattu

3) Small sentence like "This is cat" to "tac si siht"
 

Some videos you may like

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

tusharm

MrExcel MVP
Joined
May 28, 2002
Messages
11,028
If you have Laurent Longre's outstanding -- and free -- MoreFunc utility (http://longre.free.fr/english/), you can use array formula =MCONCAT(MID(C4,LEN(C4)+1-ROW(INDIRECT("1:"&LEN(C4))),1)) where C4 contains the cell to reverse.

An array formula is completed not with the ENTER key but with CTRL+SHIFT+ENTER.
 

Todd Bardoni

Well-known Member
Joined
Aug 29, 2002
Messages
3,042

ADVERTISEMENT

I wrote this function:

Code:
Function ReverseTxt(ByVal Target As Range)
    myLength = Len(Target.Value)
    For x = 0 To myLength
        ReverseTxt = Left(WorksheetFunction.Substitute(Target.Value, Left(Target.Value, x), ""), 1) & ReverseTxt
    Next x
End Function

It seems to work.
 

tusharm

MrExcel MVP
Joined
May 28, 2002
Messages
11,028
Interesting...it doesn't appear in my version of Morefunc. I guess I must have a old version of the add-in.
Aladin Akyurek said:
=TEXTREVERSE(A1)

A function from the morefunc.xll add-in.
 

tusharm

MrExcel MVP
Joined
May 28, 2002
Messages
11,028

ADVERTISEMENT

If you must write a VBA function, just use VBA's Reverse() function!

Or if you are coding for VB5, use a loop for i=len(aStr) to 1 step -1 and Mid(aStr,i,1) to extract and concatenate each character. No need for calls on Left(...Substitute(...Left())).
tbardoni said:
I wrote this function:

Code:
Function ReverseTxt(ByVal Target As Range)
    myLength = Len(Target.Value)
    For x = 0 To myLength
        ReverseTxt = Left(WorksheetFunction.Substitute(Target.Value, Left(Target.Value, x), ""), 1) & ReverseTxt
    Next x
End Function

It seems to work.
 

Ekim

Well-known Member
Joined
Jun 30, 2002
Messages
1,416
The function from the morefunc add-in should be:
=REVERSETXT(A1)

not

=TEXTREVERSE(A1)


tbardoni,
It seems to work.
Worked for everything that I threw at it.

Just for interest, here’s another UDF from Otto Moehrbach:
Code:
Function MyStrReverse(s As String) As String
Dim i As Long, rslt As String
   For i = Len(s) To 1 Step -1
      rslt = rslt & Mid(s, i, 1)
   Next i
MyStrReverse = rslt
End Function
Regards,


Mike
 

Todd Bardoni

Well-known Member
Joined
Aug 29, 2002
Messages
3,042
Ha! You're right, this is a little better
Code:
Function ReverseTxt(ByVal Target As Range)
    ReverseTxt = StrReverse(Target.Value)
End Function
:biggrin:
 

Watch MrExcel Video

Forum statistics

Threads
1,122,915
Messages
5,598,850
Members
414,263
Latest member
sherrcha

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
Top