Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Operator Question

Just getting back into vba after a couple of year stint in SAS and Coldfusion
so I'm a bit rusty. Is there something in Excel VBA that works like an IN
operator in other languages? (e.g. var IN ('code1','code2','code3')) I
don't see anything in the help so far.
Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 318
Default Operator Question

One way to do this is use Select Case

Select Case x
Case "code1","code2","code3"
........
case "code4"
.....
End select

Is this what you were looking for?

Alok

"kmbarz" wrote:

Just getting back into vba after a couple of year stint in SAS and Coldfusion
so I'm a bit rusty. Is there something in Excel VBA that works like an IN
operator in other languages? (e.g. var IN ('code1','code2','code3')) I
don't see anything in the help so far.
Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Operator Question

If you want to test whether a string is in a single variable, use
the InStr function:

Dim S As String
Dim Res As Long
S = "code1,code2,code3"
Res = InStr(1, S, "code2")
If Res 0 Then
Debug.Print "found"
Else
Debug.Print "not found"
End If

If you have an array of values, use the Match worksheet function.

Dim A As Variant
Dim N As Variant
A = Array("code1", "code2", "code3")
N = Application.Match("code2", A, 0)
If Not IsError(N) Then
Debug.Print "found"
Else
Debug.Print "not found"
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"kmbarz" wrote in message
...
Just getting back into vba after a couple of year stint in SAS
and Coldfusion
so I'm a bit rusty. Is there something in Excel VBA that works
like an IN
operator in other languages? (e.g. var IN
('code1','code2','code3')) I
don't see anything in the help so far.
Thanks



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
IF formula-simple question; simple operator Rich D Excel Discussion (Misc queries) 4 December 6th 07 03:36 PM
Operator Question James[_4_] Excel Discussion (Misc queries) 2 December 4th 07 08:32 PM
Operator kittycris Excel Worksheet Functions 3 January 11th 07 01:36 AM
what does ~ operator mean? Todd Excel Discussion (Misc queries) 3 November 22nd 05 05:30 PM
Just a question regarding a formula operator. Todd S[_3_] Excel Programming 2 October 2nd 03 05:12 PM


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