VBA equivalent to SQL ‘in’ function

calendar_today Asked Jul 9, 2013
thumb_up 8 upvotes
history Updated April 16, 2026

Question posted 2013 ยท +5 upvotes

I’m writing a conditional statement in vba like

if(userID = 1 or userID = 2 or userID = 3 or userID = 4) then
...

I was wondering if there’s a quicker, cleaner way to do this. Something like

if(userID in (1,2,3,4)) then
...

Thanks

Accepted answer +8 upvotes

An alternative would be:

select case userID
    case 1,2,3,4,5,6
       ' do something
end select

It conveys very good the meaning of the if ... then ... else construct.

Top vba Q&A (6)

+8 upvotes ranks this answer #50 out of 81 vba solutions on this site .
vba