Matt R
Matt R

Reputation: 31

Boolean, True & True & True coming in as False?

Is there a reason this is coming in as false? Below is the VBA output when debugging:

?A + B > X & A + B <= Y & C = 0
False

?A + B > X & A + B <= Y
True
?C=0
True

?A + B > X
True
?A + B <= Y
True

Upvotes: 0

Views: 411

Answers (2)

Excel Hero
Excel Hero

Reputation: 14764

The problem you are running into here is that the ampersand & is the string concatenation operator in VBA.

To evaluate logical conditions you must use the And operator, like so:

?True And True    

Upvotes: 2

Vincent G
Vincent G

Reputation: 3188

According to MSDN, Arithmetic (and &) are evaluated before Comparison and Logical operators.

So A + B > X & A + B <= Y & C = 0 evaluate as (A + B) > (X & A + B) <= (Y & C) = 0 which is probably not what you expected.

Upvotes: 0

Related Questions