I haven't figured the whole problem yet, but I think the formula somehow confuses Excel when it tries to build the dependency tree.
There are no UDFs in the formula, but it's easier to explain how I "fixed" the problem if I use UDFs.
I simplified the formula in post # 1, because I thought it would be confusing to put the actual formula in the post. I'm still simplifying it to show my "solution".
The original formula that gave the wrong result when $M38 was changed:
=If($L38,myUDF1($N38),If($M38,myUDF2($O38),0))
I added these 2 cell formulas:
$P38:=If($L38,myUDF1($N38),0)
$Q38:=If($M38,myUDF2($O38),0)
then changed my formula to:
=If($L38,$P38,If($M38,$Q38,0))
and now it works fine.
Because $N38 and $O38 are also dependent on $L38 and $M38 respectively it confused Excel when building the dependency tree. Excel determined that it had to calculate $N38 before calculating the formula, but it could not determine that it had to calculate $O38 before the formula. I'm assuming that it's because it was part of the 2nd "IF" in the formula.
By putting the 2 UDFs into separate cells then letting the formula pick a cell result instead of a UDF to run, Excel could determine that it had to calculate both $O38 and $Q38 before calculating the formula.
Bookmarks