InStrRev VBA function – How to return character position in text from the end

1. InStrRev VBA function – Description

The InStrRev VBA function   returns the character position in the string starting from the end. If we want, which position in a given text is occupied by a character or word, we should use this function. This function can also be used to search for words in text and cut them out in conjunction with the Mid VBA function  . If we would like to find the position of a string in a given text starting from the beginning, we should use the Instr function .

2. VBA InStrRev function – Syntax

'officeinside.org
InStrRev (StringCheck As String, StringMatch As String, [Start As Long = -1], [Compare As VbCompareMethod = vbBinaryCompare]) As Long

StringCheck : The text string in which we are looking for the string.

StringMatch : Search string.

Start : Optional argument. The position in the text from which to start the search. Default = -1.

Compare As VbCompareMethod : Optional argument. The type of comparison. The default value is 0. The values ​​for the argument are presented in the table below:

ConstantValueDescription
vbBinaryCompare0Binary comparison. Case sensitive.
vbTextCompare1Text comparison. It is not case sensitive

Function return : Number / Numeric value.

3. VBA InStrRev function – Example

How to use InStrRev  function  in VBA Excel? The following are examples of using the InStrRev function in the VisualBasic Editor.

Example 1 : An example of using the InStrRev VBA function – result in the MsgBox window.

'officeinside.org
 Dim strValue As String
 strValue = "Learn VBA Functions"
 MsgBox InStrRev (strValue, "f")
 MsgBox InStrRev (strValue, "a", -1)
 MsgBox InStrRev (strValue, "A", -1)

Example 2 : VBA InStrRev – function example – result in an Excel sheet.

'officeinside.org 
 Dim strValue2 As String
 strValue2 = "Learning VBA functions"
 Range ("A1") = InStrRev (strValue2, "f")
 Range ("A2") = InStrRev (strValue2, "a", -1)
 Range ("A3") = InStrRev (strValue2, "A", -1)
Excel VBA Functions - InStrRev VBA function
Excel VBA Functions – InStrRev VBA function

4. VB InStrRev function – Additional information

  • none

5. InStrRev VisualBasic function – Where to use?

The function can be used in: Excel 2003, Excel 2007, Excel 2010, Excel 2013, Excel 2016.

The article is part of the VBA Excel function list. You can find a list of all VBA functions at this address:  VBA functions .

Leave a comment

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

%d bloggers like this: