ms access vba check if string contains code example
Example 1: VBA check if a cell contains a letter or string
Sub IfContains()
If InStr(ActiveCell.Value, "string") > 0 Then
MsgBox "The string contains the value."
Else
MsgBox "The string doesn't contain the value."
End If
End Sub
Example 2: excel vba string contains
Dim SearchString, SearchChar, MyPos
SearchString ="XXpXXpXXPXXP"
SearchChar = "P"
MyPos = Instr(4, SearchString, SearchChar, 1)
MyPos = Instr(1, SearchString, SearchChar, 0)
MyPos = Instr(SearchString, SearchChar)
MyPos = Instr(1, SearchString, "W")