Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
J@Y J@Y is offline
external usenet poster
 
Posts: 127
Default 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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
J@Y J@Y is offline
external usenet poster
 
Posts: 127
Default 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.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Case Statement Katie Excel Worksheet Functions 13 December 1st 08 07:32 PM
For...Next or Select Case Statement VBA_Newbie79[_2_] Excel Programming 3 July 2nd 07 08:44 PM
select case statement? CR[_2_] Excel Programming 5 December 20th 06 09:21 PM
Select Case within IF-Else statement rwnelson Excel Programming 8 April 6th 06 06:47 PM
select case statement jrd269[_4_] Excel Programming 4 June 3rd 05 04:22 PM


All times are GMT +1. The time now is 07:38 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"