G
Greg
Hello,
The VBA help file for the Select Case statement says the test
expression should be a numeric or string expression. I am trying to
use a Select Case statement to perform a Like comparison on a test
string. Test1 below illustrates one of many failed attempts to use
"myString" as the test expression and a Like statement in the Case
statement.
Sub Test1()
Dim myString As String
myString = "ABCD"
Select Case myString
Case Like "A??D" 'Compile error here
MsgBox "Match"
Case Else
MsgBox "No match found"
End Select
End Sub
I did discover however, that I could use the boolean value "True" as a
test expression and the Select Case routing works as expected.
Sub Test2()
Dim myString As String
myString = "ABCD"
Select Case True
Case myString Like "A??D"
MsgBox "Match"
Case Else
MsgBox "No match found"
End Select
End Sub
Questions: Is there a way to use a string expression as the test
expression and Like in the Case statements? Would using the boolean
value True as the test expression cause instability or introduce errors
in procedure?
Thanks
The VBA help file for the Select Case statement says the test
expression should be a numeric or string expression. I am trying to
use a Select Case statement to perform a Like comparison on a test
string. Test1 below illustrates one of many failed attempts to use
"myString" as the test expression and a Like statement in the Case
statement.
Sub Test1()
Dim myString As String
myString = "ABCD"
Select Case myString
Case Like "A??D" 'Compile error here
MsgBox "Match"
Case Else
MsgBox "No match found"
End Select
End Sub
I did discover however, that I could use the boolean value "True" as a
test expression and the Select Case routing works as expected.
Sub Test2()
Dim myString As String
myString = "ABCD"
Select Case True
Case myString Like "A??D"
MsgBox "Match"
Case Else
MsgBox "No match found"
End Select
End Sub
Questions: Is there a way to use a string expression as the test
expression and Like in the Case statements? Would using the boolean
value True as the test expression cause instability or introduce errors
in procedure?
Thanks