The Excel property
Precedents.Count is returning a different value within a cell formula than the value shown when calling the same function within the immediate window.
See below for the function and testing code.
Function CountPrecedents() CountPrecedents = Range("A1").Precedents.Count End Function Sub TestCountPrecedents() Range("A1").Formula = "=B1+B2" Range("C1").Formula = "=CountPrecedents()" Debug.Print "The cell value is " & Range("C1").Value Debug.Print "The true function value is " & CountPrecedents() End Sub
TestCountPrecedents in the Immediate window results in the following output:
The cell value is 1 The true function value is 2
Why would the cell function have a different value than the immediate window? I cannot replicate this behavior with other