SQL IN function or Data validation in VBA

cgclower

New Member
Joined
Feb 28, 2010
Messages
40
I am wondering if there is a way to check the value of a variable against a list within my vba code. Sort of like using data validation, but instead of referencing a range on a worksheet, it would reference a list stored directly in my code. I envision something like:
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Dim List as integer
Dim ChangingVariable as integer
<o:p></o:p>
List = ( any of the numbers 1,2,3,4,5,6,7 or 8) ‘or whatever the code should be
<o:p></o:p>
' do some stuff that ends up with ChangingVariable = 3
<o:p></o:p>
If ChangingVariable = List then ' i.e. if the number is in the list
' do some stuff
Else
' do some other stuff
End If
<o:p></o:p>
If this was SQL I would think of using the IN function, but as far as I can tell that doesn’t work in VBA.

Thanks for the help!
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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