In my code i want to use if condition. In which i want to use “OR” around 18 times.
Like for e.g.
If a="something" or a="something" or a="something" or.........(up to 18 times)... then
'do nothing
else
'do action
end if
[Note : value of a is changing in For loop every time]
so i just want to ask does there any limitation in IF for using OR in limited times.
OR is there any other better way to do the same.
Thanks
As far as I know, there is no limitation when using
ORthis way.Yet, you may consider alternative ways of coding this.
Negating a condition using Not
First, if you
do nothingin the first case, then consider using theNotstatement:Consider using Select Case
Second, if you are checking the very same variable, you could either consider using a
Select Casebut it doesn’t seem appropriate in your case if you have only one case.Try to use a search
Eventually, if you are checking strings, you could probably better use a search within an array (with
Application.Matchif you are within Excel or.Contains) or within a String usingInstr.Using a collection or a dictionary
[EDIT] Another very good way to handle this would be to use the Dictionary Structure of VBA and check if
aexists (see MSDN for some information).