InStr returns the first occurrence of a string inside another string.
InStr([start,] string1, string2 [, compare])
- start
- Optional. Character position where the search starts. If omitted, the search starts at the start of string1, position 1. Valid input values: 1 to Len(string1)
- string1
- The string to search in. Can be
Null. - string2
- The string to find. This is the text you want to find inside string1. It is usually shorter than string1. Can be
Null. - compare
- Optional. Specifies the type of string comparison.
vbBinaryCompare(0) performs a fast binary comparison where each character matches only itself. This is the default.vbTextCompare(1) performs a text comparison.vbDatabaseCompare(2). For Microsoft Access (Windows only), performs a comparison based on information contained in your database.- If you omit compare, InStr will use the setting of the
Option Comparestatement.
- Binary comparison is the safest option. Text comparison rules vary by the system locale. In text comparison, what matches on one computer may not match on another.
Return value
InStr returns one of the following values:
Nullif either string1 or string2 isNull.- start if string2 is empty.
- Character position of the first occurrence of string2 in string1.
- Zero if string2 was not found in string1.
Special cases:
- InStr(string1, "") returns 1 if string1 is not empty.
- InStr("", "") returns 0.
- If start exceeds the length of string1, there is never a match and InStr returns 0.




