VBA STRREVERSE Function

VBA StrReverse Function

Overview of VBA StrReverse Function:

VBA StrReverse function is categorized as a Text/String function in VBA. It is a built-in function in MS Office Excel. It reverse a given string. It has one mandatory String parameter. If input string has Null, then it returns zero(0). It could be used only in VBA function. We can not use this function as Excel function. The StrReverse function can be used in either procedure or function in a VBA editor window in Excel. We can use this VBA StrReverse function any number of times in any number of procedures or functions. In the following section we learn what is the syntax and parameters of the StrReverse function, where we can use this StrReverse function and real-time examples in VBA.

Table of Contents:

Syntax of VBA StrReverse Function

The syntax of the VBA StrReverse function is

StrReverse(Expression)

Note: This StrReverse function founds the StrReversegth of specified string.

Parameters or Arguments

This function has one mandatory parameter or argument for the StrReverse Function.
Where
Expression: The expression is a mandatory argument. The expression is the string which we want to reverse a string.

Where we can apply or use the VBA StrReverse Function?

We can use this VBA StrReverse function in MS Office 365, MS Excel 2016, MS Excel 2013, 2011, Excel 2010, Excel 2007, Excel 2003, Excel 2016 for Mac, Excel 2011 for Mac, Excel Online, Excel for iPhone, Excel for iPad, Excel for Android tablets and Excel for Android Mobiles.

Example 1: Reverses a given string: “AWESOME”

Here is a simple example of the VBA StrReverse function. This below example macro returns the StrReversegth a given string (Includes numbers).

'Reverses a given string: "AWESOME"
Sub VBA_StrReversee_Function_Ex1()

    Dim sString As String, sSubString As String
    
    sString = "AWESOME"
    sSubString = StrReversee(sString)
    
    MsgBox "The given string in reverse is :" & sSubString, vbInformation, "VBA StrReversee Function"

End Sub

Output: Here is the screen shot of the first example output.
VBA StrReverse Function

Example 2: Reverses a given string: “Life is beautiful”

Here is a simple example of the VBA StrReverse function. This below example macro reverses a given string.

'Reverses a given string: "Life is beautiful"
Sub VBA_StrReversee_Function_Ex2()

    Dim sString As String, sSubString As String
    
    sString = "Life is beautiful"
    
    sSubString = StrReversee(sString)
    
    MsgBox "The given string in reverse is :" & sSubString, vbInformation, "VBA StrReversee Function"
    
End Sub

Output: Here is the screen shot of the second example output.
VBA StrReverse Function

Example 3: Reverses null string

Here is a simple example of the VBA StrReverse function. This below example returns an error. We can’t reverse null string.

'Reverses null string
Sub VBA_StrReversee_Function_Ex3()

    Dim sString As String, sSubString As String
    
    sString = Null
    
    sSubString = StrReversee(sString)
    
    MsgBox "The given string in reverse is :" & sSubString, vbInformation, "VBA StrReversee Function"
    
End Sub

Output: Here is the screen shot of the third example output.
VBA StrReverse Function

Example 4: Reverses a given string: “123456789”

Here is a simple example of the VBA StrReverse function. This below example macro reverses a given string.

'Reverses a given string: "123456789"
Sub VBA_StrReversee_Function_Ex4()

    Dim sString As String, sSubString As String
    
    sString = "123456789"
    
    sSubString = StrReversee(sString)
    
    MsgBox "The given string in reverse is :" & sSubString, vbInformation, "VBA StrReversee Function"
    
End Sub

Output: Here is the screen shot of the fourth example output.
VBA StrReverse Function

Instructions to use Macro Codes

Here are the step by step instructions to use the VBA StrReverse function in Excel VBA.

  • Open an Excel workbook.
  • Press Alt+F11 to open VBA Editor window.
  • Go to Insert menu and click on module from the available options.
  • Copy above specified macros to the VBA editor.
  • Select any procedure from above codes and click on ‘Run’ command or use Keyboard shortcut ‘F5’.

Complete List of VBA Functions:

Please click on below link to go back to see all List of VBA Functions.
List of VBA Functions

Leave a Comment

Your email address will not be published. Required fields are marked *