Try the Like operator:
Const testString = "ABABA"
Dim myChar1 As String, myChar2 As String
'// test 1/3/5
myChar1 = Mid(testString, 1, 1)
'// test2/4
myChar2 = Mid(testString, 2, 1)
If testString Like myChar1 & "[A-Z]" & myChar1 & "[A-Z]" & myChar1 Then
MsgBox "Matches 1, 3 and 5"
ElseIf testString Like "[A-Z]" & myChar2 & "[A-Z]" & myChar 2 & "[A-Z]" Then
Msgbox "Matches 2 and 4"
End If
Or use the Mid() function:
If Mid(testString, 1, 1) = Mid(testString, 3, 1) And _
Mid(testString, 3, 1) = Mid(testString, 5, 1) And _
Mid(testString, 1, 1) = Mid(testString, 5, 1) Then
MsgBox "Matches 1, 3 and 5"
ElseIf Mid(testString, 2, 1) = Mid(testString, 4, 1) Then
MsgBox "Matches 2 and 4"
End If
OR to check for both conditions:
Dim match1 As String, match2 As String
Const testString As String = "ABABA"
match1 = Left(testString, 1) & "[A-Z]" & Left(testString, 1) & "[A-Z]" & Left(testString, 1)
match2 = "[A-Z]" & Left(testString, 1) & "[A-Z]" & Left(testString, 1) & "[A-Z]"
If testString Like match1 Or testString Like match2 Then
MsgBox "findwindow likes it when anything matches"
End If
=AND(MID(A1,1,1)=MID(A1,3,1), MID(A1,1,1)=MID(A1,5,1)). That will return TRUE if first character is the same as 3rd and 5th.=MID(A1,2,1)=MID(A1,4,1)will return TRUE if 2nd and 4th characters match