Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

VBA-Excel : Strings Functions – InstrRev

Descrip­tion:

Instr­Rev: This func­tion returns the posi­tion of last occur­rence of a string into another string, as a vari­ant, based upon the argu­ments are pro­vided, OR you can say that it returns the posi­tion of the first occur­rence of a string into another string from the end of the string.

For­mat:

InStr­Rev(main­String, searchedString[,start, ] [, compare])

Argu­ments:

  • main­String
      • Manda­tory
      • Type: String
      • String being searched.

  • ·searched­String
    • Manda­tory
    • Type: String
    • String to be searched
  • start
    • Optional
    • Type: Numeric
    • Start­ing posi­tion from where search has to be started.(from end of the string, if string length is 10 then it starts with 10 to 1)
    • Required if com­pare argu­ment is specified
  • Com­pare
    • Optional
    • Spec­ify type of string comparison.
    • Set­tings
Con­stant Value
Descrip­tion
vbBina­ryCompare 0 Per­forms a binary comparison.
vbTextCom­pare
1 Per­forms a tex­tual comparison.
vbData­baseC­om­pare 2 Microsoft Access only. Per­forms a com­par­i­son based on infor­ma­tion in your database.
INSTRRev

INSTR­Rev

Results:

Con­di­tion Result
main­String is zero-length 0
main­String is NULL NULL
searched­String is zero-length Start
searched­String is NULL NULL
searched­String is not found 0
searched­String found in mainString Posi­tion at which match is found
Start> searchedString 0

 

Function FnInstrRevOperations()

   Dim mainString

   Dim searchString

   mainString = "SumitJain"

   searchString = "i"

   MsgBox "Position of 'i' is " & InStrRev(mainString, searchString, 9, vbTextCompare)

   ' Output : Position is 'i' is 8
 

End Function

 

Also Read About  Other String() Functions

INSTR()                       |                         Instr­REV()                       |                        LCase()

UCase()                      |                         Left()                                |                        Right()

LTrim()                        |                         Mid()                                 |                        Trim()

RTrim()                       |                        Replace()                          |                        Space()

Len()                           |                        Str­Comp()                         |                        String()

Happy Macro­ing :)

Sumit Jain

You may also like...

Leave a Reply

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

%d bloggers like this: