ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using Like Statement in Select Case (https://www.excelbanter.com/excel-programming/394117-using-like-statement-select-case.html)

J@Y

Using Like Statement in Select Case
 
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.

Jim Thomlinson

Using Like Statement in 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

--
HTH...

Jim Thomlinson


"J@Y" wrote:

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.


J@Y

Using Like Statement in Select Case
 
Great thanks!

"Jim Thomlinson" wrote:

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

--
HTH...

Jim Thomlinson


"J@Y" wrote:

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.



All times are GMT +1. The time now is 10:59 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com