Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default VBA equivalent for SQL 'IN' function

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?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default VBA equivalent for SQL 'IN' function

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

Tim

--
Tim Williams
Palo Alto, CA


"Mitch" wrote in message
...
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?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA equivalent for SQL 'IN' function


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

--
tony
-----------------------------------------------------------------------
tony h's Profile: http://www.excelforum.com/member.php...fo&userid=2107
View this thread: http://www.excelforum.com/showthread.php?threadid=50748

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default VBA equivalent for SQL 'IN' function

Thank you Tim. I'll see if I can make it work.

"Tim Williams" wrote:

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

Tim

--
Tim Williams
Palo Alto, CA


"Mitch" wrote in message
...
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?




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default VBA equivalent for SQL 'IN' function

Thanks Tony. I think that the 3rd method will work.

"tony h" wrote:


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

Regards


--
tony h
------------------------------------------------------------------------
tony h's Profile: http://www.excelforum.com/member.php...o&userid=21074
View this thread: http://www.excelforum.com/showthread...hreadid=507480


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
NZ function equivalent in Excel jg Excel Worksheet Functions 7 April 21st 23 05:15 PM
Function Equivalent need ytayta555 Excel Worksheet Functions 6 May 7th 08 02:53 PM
equivalent for function , please for help ytayta555 Excel Worksheet Functions 5 April 21st 08 02:03 AM
Looking for the equivalent of a Maxif function PerplexedinKY Excel Discussion (Misc queries) 6 January 20th 07 03:57 AM
What is the Excel equivalent of the CELL function? JP Excel Worksheet Functions 8 September 5th 06 12:49 AM


All times are GMT +1. The time now is 07:03 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"