InStr
Returns the character position of the first occurrence of String2 within String1.
Syntax
InStr(StartPos, StringToSearch, StringToMatch)
StartPos:
A numeric expression that sets the starting position for the search. If omitted, search begins at the first character position. If Num contains Null, an error occurs. An Integer or expression representing a valid numeric value.
StringToSearch:
The string expression being searched. A string or expression that can represent a valid text value.
StringToMatch:
The string expression being searched for. A string or expression that can represent a valid text value.
Return Value
Returns a variant containing a Long data type indicating the result of the string search. Returns 0 if:
Returns a value representing the count position where character match was first found.
Returns Null if StringToSearch or StringToMatch contains null.
Related Functions
IsNull | Left, Left$ | Mid | Right | StrComp
Example
Dim strToSearch as String
Dim strToFind as String
Dim lngPosition as Long
strToSearch = "Good Bye"
' note this has an uppercase "B"
strToFind = "bye"
' note this has a lowercase "b"
lngPosition = InStr(1, strToSearch, strToFind, 0)
' returns 0 (Did not find match)
lngPosition = InStr(1, strToSearch, strToFind, 1)
' returns 6 (Position of first character in match)