Reverse numbers and text

uttamsaxena

Board Regular
Joined
Apr 22, 2003
Messages
182
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"
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
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.
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0
Ha! You're right, this is a little better
Code:
Function ReverseTxt(ByVal Target As Range)
    ReverseTxt = StrReverse(Target.Value)
End Function
:-D
 
Upvote 0

Forum statistics

Threads
1,224,884
Messages
6,181,572
Members
453,054
Latest member
arz007

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