Wednesday, November 26, 2008

Reverse a Cell text or Cell value


Hi All,

Today we are know about how to reverse a cell value. Means if you input "RAM" in cell A1 then it returns you "MAR" in other cell.

For doing this we make a custom function. We called the function rvrsstring.

Now, Open a new excel file then open visual basic editor by press Alt+F11 or by the following path,
Tools>macro>visual basic editor.

Now insert a new module, by Insert>module. Now paste following codes.

Public Function rvrsstring(loecell As Range, Optional istext As Boolean) Dim i As Integer Dim strnew As String Dim strold As String strold = Trim(loecell) For i = 1 To Len(strold) strnew = Mid(strold, i, 1) & strnew Next i If istext = False Then rvrsstring = CLng(strnew) Else rvrsstring = strnew End If End Function

Exit from visual basic editor and save the excel file.

Here is a sample:
Enter RAM on cell A1 and you want your result in C1 for this write a formula in cell C1 "=rvrstirng(A1,true)" this formula give you result which is "MAR".


If you want to reverse a long integer value then you can put "=rvrsstring(A1,False)"


If you put a wrong formula it shows you a error.


Here you can see a cLng commands here is a short description about cLng commands in Vba.

In Excel, the CLng function converts a value to a long integer.

The syntax for the CLng function is:

CLng(expression)

Applies To:

  • Excel 2007, Excel 2003, Excel XP, Excel 2000
For more details about CLng commands you can visit the Link
Sample File: Click here

If you want to use this function on your every workbook download the following addins

Addins: Click here

No comments:

Subscribe Now: From your browser

Search:

Learn Office Excel