vba search string position code example
Example 1: excel vba multiple string search with InStr function
'VBA function to check if ANY of a list of substrings is contained
'within a string:
Function AnyIn(s$, ParamArray checks()) As Boolean
Dim e
For Each e In checks
If InStrB(s, e) Then AnyIn = True: Exit Function
Next
End Function
'-------------------------------------------------------------------
MsgBox AnyIn("abcde", "o", 5, "z", "a") '<--displays: True
MsgBox AnyIn("abcde", "o", 5, "z", "p") '<--displays: False
Example 2: vba search string position
'Position of "DOG" from 8th character, case insensitive
Debug.Print InStr(8, "My Dog is a dog", "DOG", vbTextCompare) ' 13