IN function

abenitez77

Board Regular
Joined
Dec 30, 2004
Messages
149
Is there an IN function in excel vba that I can use ?
In SQL I can do something like this:

Select * from table where field IN('value1','value2','value3','value4')

Is there something similar that I can do in Excel?

I have this If statement below that I want to do this to:

If LCase(xSheetName) = "price strat export" Or LCase(xSheetName) = "a-b-c moves 2" Or LCase(xSheetName) = "test" _
Or LCase(xSheetName) = "forecasts" Or LCase(xSheetName) = "q4 skeleton" Or LCase(xSheetName) = "ly space and sales" _
Or LCase(xSheetName) = "p_template" Or LCase(xSheetName) = "fills" Or LCase(xSheetName) = "input plan" _
Or LCase(xSheetName) = "customer" Then
GoTo NextCounter
End If
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
One suggestion:
Code:
    Dim sNames As String
    sNames = "price strat export|a-b-c moves 2|test|...|customer"


    If InStr(sNames, LCase(xSheetName)) > 0 Then
       GoTo NextCounter
    End If
Where "..." are the missing sheet names - adjust as required.
 
Last edited:
Upvote 0
Another option:

Code:
    myNames = Array("price strat export", "a-b-c moves 2", "test")
    
    If UBound(Filter(myNames, LCase(xSheetName))) > -1 Then
    
    ' Do something
    
    End If
 
Upvote 0
One suggestion:
Rich (BB code):
    Dim sNames As String
    sNames = "|price strat export|a-b-c moves 2|test|...|customer|"


    If InStr(sNames, "|" & LCase(xSheetName) & "|") > 0 Then
       GoTo NextCounter
    End If
Where "..." are the missing sheet names - adjust as required.
I would suggest making the four additions I show in red above in order to make sure you don't register a partial match as if it were a full match.
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,224
Members
452,620
Latest member
dsubash

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top