Instr

Public Function Instr(ByVal Start As Variant, ByVal SourceString As String, Optional ByVal FindString As String, Optional ByVal Comparemode As Long = 0) As Long

Searches the SourceString starting from Start for a FindString and returns the found position (1-based) or 0 (not found). Please note: if the function is used with 2 parameters, the first is treated as SourceString, the 2nd parameter as FindString. Start in then assumed 1. If used with 3 or 4 parameters, the first parameter is assumed to be the Start.

SendDebug(Instr("Hello world", "w")) 'Prints the first occurrance of 'e', 2
SendDebug(Instr(1, "Hello world", "O", vbTextCompare)) 'Prints the first occurrance of 'O', 5
SendDebug(Instr(1, "Hello world", "O", vbBinaryCompare)) 'Prints the last occurrance of 'O' (case sensitive, not found), 0

See also: