Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check against a list of values in an IF statement?

I am trying to write an IF statement like this:

if var [is any of 1,4,5,6,12] then do stuff

But I don't know the syntax for this in VBA, other than:

if var=1 or var=4 or var=5...

which seems a bit clumsy. Is there a different way?

like image 511
horace_vr Avatar asked Sep 10 '15 13:09

horace_vr


1 Answers

You can use a Select Case statement:

select case var
case 1,4,5,6,12
  'do something
case else
  'alternative
end select
like image 77
psychicebola Avatar answered Sep 21 '22 16:09

psychicebola