0

In Java or C#, AND statements are evaluated from left to right. If the first condition is not true, then the second condition is not evaluated. Which is useful if your second condition will cause an java.lang.arrayindexoutofboundsexception.

I have a similar case in my Excel-VBA application. I have an if statement as such:

If condition1 = false And cellElement - 1 <> "" Then ...

It throws a VBA - Run Time Error 1004 'Application Defined or Object Defined Error', even if condition1 is false.

My question is, does VBA evaluate the second condition in an AND statement, even if the first condition is false?

My current work around is ugly, but it works:

Dim b As Boolean
If condition1 = false Then
   b = false
Else
   b = cellElement - 1 <> ""

If b Then...

Thank you!

Daryl Bennett
  • 462
  • 10
  • 22

0 Answers0