Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel: simple question for repetitive Or's

Status
Not open for further replies.

azzi2000

MIS
Jan 28, 2004
145
US
There must be a simpler command to find match for a numerous conditions.
I have the following code:
if ws.name = sSheet1 Or ws.name=sSheet2 or Ws.name=sSheet3....
there must be something like this:
if ws.name in (sSheet1, sSheet2..) then
....
Please advice,
Thank you.
Dré
 
Take a look at the Select Case instruction.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
List all your possibilities in an array and loop through the array item by item.

Or

Select Case statement.
 
Available in VBA6+ (office 2k+):

strTested = "a"
If UBound(Filter(Array("a", "b", "c"), strTested)) = -1 Then
MsgBox "No match"
Else
MsgBox "Item in list"
End If

combo
 


AS PHV suggested the Case Statement would do the job handily
Code:
Select Case ws.Name 
   Case "S1", "S2", "S3"
      'stuff to do for any of these sheets

   Case Else
      'otherwise

End Select


Skip,

[glasses] [red]Be advised:[/red]When Viscounts were guillotined just as they were disclosing where their jewels were hidden, it shows to go that you should...
Never hatchet your Counts before they chicken! [tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top