Leading the way in Microsoft Office Development
 Home|Excel|Word|PowerPoint|Consultancy|Feedback|Contact 
 Microsoft Excel > Functions User Defined > REVERSE< Previous | Next > 

 

REVERSE(sCellContents)

 
 

Returns the contents of a cell with all the characters reversed.

 

 
sCellContentsThe number or text you want to reverse.
 

 

REMARKS

 
 
  • If the argument is not a number or a text string, then #N/A is returned.

     
     
  • This function will not work in Excel 97 because the VBA function StrReverse does not exist.

     

     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    Option Explicit

    Public Function REVERSE(ByVal sCellContents As String) As String

       Call Application.Volatile(True)

       If Application.WorksheetFunction.IsNonText(sCellContents) = True Then
          REVERSE = VBA.CVErr(xlErrNA)
       Else
          REVERSE = VBA.StrReverse(sCellContents)
       End If

    End Function
       

     

    Example

     
       

     

    Excel 97

     
     

    If you need to use this function in Excel 97 then you can use the following function:

     
     
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    Public Function REVERSE97(ByVal sCellContents As String) As String
    Dim ichar As Integer
       If Application.WorksheetFunction.IsNonText(sCellContents) = True Then
          REVERSE97 = VBA.CVErr(xlErrNA)
       Else
          For ichar = Len(sCellContents) To 1 Step -1
             REVERSE97 = REVERSE97 & Mid(sCellContents, ichar, 1)
          Next ichar
       End If
    End Function
       

     Copyright © 2004-2007 Better Solutions Limited. All Rights Reserved.< Previous | Top | Next >