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."
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: