Using Like Statement in Select Case

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to include Like in a Case?

Ie:

dim str as string

Select case str

(Case 1): If Str CONTAINS "blah"

end select

Its like writing If str like "*blah*" then... but with select case.
 
Use InStr to return the position of "blah" within the string. Something like
this

Sub Test()
Dim str As String

str = "This and That"
Select Case True
Case InStr(1, str, "This")
MsgBox "Found this"
Case InStr(1, str, "That")
MsgBox "Found That"
Case InStr(1, str, "abcd")
MsgBox "Found ABCD"
End Select
End Sub
 
Great thanks!

Jim Thomlinson said:
Use InStr to return the position of "blah" within the string. Something like
this

Sub Test()
Dim str As String

str = "This and That"
Select Case True
Case InStr(1, str, "This")
MsgBox "Found this"
Case InStr(1, str, "That")
MsgBox "Found That"
Case InStr(1, str, "abcd")
MsgBox "Found ABCD"
End Select
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top