Using Instr with Optional Backward Search
Below code can be used to find the starting position of a string in a text from start or can be used to search backward as well.
You can also download the attachment.
Option Explicit Function lngFindString(strFullString As String, strSearchString As String, _ blnCaseSensitive As Boolean, blnReverseSearch As Boolean) As Long If blnCaseSensitive Then If Not blnReverseSearch Then lngFindString = InStr(1, strFullString, strSearchString) Else lngFindString = InStrRev(strFullString, strSearchString, , vbBinaryCompare) End If Else If Not blnReverseSearch Then lngFindString = InStr(1, strFullString, strSearchString, vbTextCompare) Else lngFindString = InStrRev(strFullString, strSearchString, , vbTextCompare) End If End If End Function Sub ExecuteFunction() MsgBox lngFindString("Look into my eyes! Look Please", "look", False, True) End Sub
»
- Vishesh's blog
- Login or register to post comments
- 9806 reads
Recent comments
5 years 41 weeks ago
6 years 27 weeks ago
6 years 39 weeks ago
6 years 42 weeks ago
6 years 43 weeks ago
6 years 48 weeks ago
7 years 4 weeks ago
7 years 5 weeks ago
7 years 5 weeks ago
7 years 5 weeks ago