Does the VBA "And" operator evaluate the second argument when the first is false?
What you are looking for is called "short-circuit evaluation".
VBA doesn't have it.
You can see an approach that is probably adaptable to your situation here.
The approach that was chosen there involved substituting a Select Case
for the If
. There is also an example of using nested Ifs
.
As DOK mentioned: No, VBA does not have short-circuit evaluation.
It's technically more efficient to use 2 If-then
statements instead of using the AND
operator, but unless you are doing it a lot of times, you wouldn't notice the savings, so go for whatever is more readable. And if you want to get really technical, VBA handles multiple If-then
statements faster than Select Case
ones as well.
VBA is quirky :)