VBA string find

You can find a sub-string in a string by using instr(start,str,sub-str[,Compare])
-start specified the start position in the str string where the search begins.
-str is the string that contains the sub-string.
-sub-str is the string being searched for.
-Compare specifies the comparision mode. If you specify vbBinaryCompare, the comparison is case-sensitive. This means that AB is not the same as ab, Ab, or aB. If you specify vbTextCompare, the comparison is case-insensitive. Therefore, AB,ab,Ab,aB are the same. The function returns 0 if the sub-string is not found in the string. Otherwise it returns the position of the first occurrence of the sub-string.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
     Dim str As String
     str = "VBA stands for Visual Basic for Applications." & _
     "VBA is a useful programming language for Microsoft Office Applications." & _
     "such as MS Excel, MS Access, MS Outlook, etc."
     Dim pos As Integer
     pos = InStr(1,str, "VBA", vbBinaryCompare)
     If Not (pos = 0) Then
      MsgBox "It is found."
     End If
    
End Sub

Posted by: Lavy | post date: 02-23-2013 | Subject: VBA for MS Excel




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.