Tuesday, February 08, 2011

Invert text in a cell

 

If cell A1 contains:
microsoft excel

The formula/function in cell B1:
=ReverseCell(A1,TRUE)

returns:
lecxe tfosorcim

 

Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

Adding the Macro
1. Copy the below macro, by highlighting the macro code and pressing the keys CTRL+C
2. Open your workbook
3. Press the keys ALT+F11 to open the Visual Basic Editor
4. Press the keys ALT+I to activate the Insert menu
5. Press M to insert a Standard Module
6. Paste the code by pressing the keys CTRL+V
7. Press the keys ALT+Q to exit the Editor, and return to Excel.

Code:

Option Explicit
Function ReverseCell(Rcell As Range, Optional IsText As Boolean)
'http://www.ozgrid.com/VBA/ReverseCell.htm
'Enter the function like this for text:
'=Reversecell(A1,TRUE)
'Or either of the ways below for numeric data
'=Reversecell(A1,FALSE)
'=Reversecell(A1)
'
Dim i As Integer
Dim StrNewNum As String
Dim strOld As String
strOld = Trim(Rcell)
For i = 1 To Len(strOld)
  StrNewNum = Mid(strOld, i, 1) & StrNewNum
Next i
If IsText = False Then
  ReverseCell = CLng(StrNewNum)
Else
  ReverseCell = StrNewNum
End If
End Function

 

 

Came from : http://excel.bigresource.com/Track/excel-cBcjrDfS/ thanks !

Post a Comment

Blog Archive