VBA equivalent for SQL 'IN' function

G

Guest

SQL, SAS and other 'languages' have a set function that allows the developer
to determine whether a variable's value exists within a set identified in the
'IN' statement; e.g. If myVar in ("A","B","C") then .....
Is there a VBA equivalent?
 
T

Tim Williams

msgbox
Application.WorksheetFunction.match("help",Array("this","might","help"),0)

Tim
 
T

tony h

I am not sure of a direct equivalent but three options:
1. You could use a delimited list and then

if instr(1, "!A!B!C!" , "!" & myvar & "!") <> 0 then etc

2. use

Select Case myvar
Case "A", "B", "C"
'do my stuff
End Select


3 create your own function to do it such as

Function myIN(strSearch, ParamArray strIN()) As Boolean
Dim v As Variant

myIN = False

For Each v In strIN()
If strSearch = v Then
myIN = True
Exit For
End If
Next
End Function

if myin(myvar,"B","C","A") then

Regard
 

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

Top