jeudi 22 février 2018

Excel VBA AND OR operator combo in If statement causing short

I have been struggling to find a solution to this problem. Everywhere I look people say that VBA does not "short-circuit" when validating AND OR conditions. However, I cannot find anything else to say otherwise. Please tell me how to disable the "short" or rewrite the code to make it work.

Adding watches to all of the variables and debugging shows that it occurs at the statement and not another condition later that could alter the value.

The variable inputs are:

One spot in the array:

Sign2= "=",   Sign3 = "+",   SC1 = "",    SC2 <> "",   SC3<>""

Later in the array:

Sign2= "=",   Sign3 = "+",   SC1 <> "",    SC2 = "",   SC3<>""

This is the specific condition that is giving me trouble:

If (Sign2 = "=" And Sign3 = "+" And ((SC1(i, j) <> "" Or SC2(1, j) <> "") And SC3(i, j) <> "") Then
Result(i, j) = "X"
Else

The output will change if I simply switch SC1 and SC2 in the code. either way, when analyzing the code if the first value in the OR statement is false then it will not output the value.

Aucun commentaire:

Enregistrer un commentaire