Instr() function is used to return the position of a substring in a string.
The syntax for the InStr function is:
InStr( [start], string_being_searched, string2, [compare] )
start is optional. It is the starting position for the search. If this parameter is omitted, the search will begin at position 1.
string_being_searched is the string that will be searched.
string2 is the string to search for.
compare is optional. This is the type of comparison to perform. The valid choices are:
- vbUseCompareOption
- vbBinaryCompare
- vbTextCompare
- vbDatabaseCompare
Example
Excel
InStr(1, "My excel example", "ex")
The above example would return 10.
VBA
myPosition = InStr(1, "My excel example", "ex")
In the above example, myPosition will now contain the value 10.