Learn how to use the Excel INSTR function with syntax and examples.
The Microsoft Excel INSTR function returns the position of the first occurrence of a substring in a string.
The syntax for the Microsoft Excel INSTR function is:
InStr( [start], string, substring, [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 is the string to search within.
substring is the substring that you want to find.
compare is optional. It is the type of comparison to perform. It can be one of the following values:
|vbUseCompareOption||-1||Uses option compare|
The INSTR function can be used in the following versions of Microsoft Excel:
The INSTR function can be used in Microsoft Excel as the following type of function:
The INSTR function can only be used in VBA code in Microsoft Excel.
Let's look at some Excel INSTR function examples and explore how to use the INSTR function in Excel VBA code:
InStr(1, "Tech on the Net", "the") Result: 9 InStr("Tech on the Net", "the") Result: 9 InStr(10, "Tech on the Net", "t") Result: 15
Dim LPosition As Integer LPosition = InStr(10, "Tech on the Net", "t")
In this example, the variable called LPosition would now contain the value 15.