title: Excel is calculating a formula with a VBA function as an error unless it is re-entered
body: <p>I've got a simple if statement set up in a worksheet where the if condition is VBA user defined function:</p>
  
  <pre><code>Function CellIsFormula(ByRef rng)
      CellIsFormula = rng(1).HasFormula
  End Function
  </code></pre>
  
  <p>This function seems to work fine:</p>
  
  <p><img src="https://i.stack.imgur.com/EusEg.png" alt="Evaluate 1">
  <img src="https://i.stack.imgur.com/vzx1d.png" alt="Evaluate 2"></p>
  
  <p>But for some reason that I can't figure out, the cell is evaluating to an error. What's worse, is when evaluating the formula, excel is attributing the error to a calculation step that doesn't produce an error:</p>
  
  <p><img src="https://i.stack.imgur.com/WEUf2.png" alt="Evaluate 4">
  <img src="https://i.stack.imgur.com/xYqE4.png" alt="Evaluate 5">
  <img src="https://i.stack.imgur.com/p6oDi.png" alt="Evaluate 6"></p>
  
  <p>To top it all off, and what really blows my mind, is that if I simply re-enter the formula, or force a full recalculation (<kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>F9</kbd>) - the formulas evaluate no problem!</p>
  
  <p><img src="https://i.stack.imgur.com/Ra9N6.png" alt="Re-Enter Formula">
  <img src="https://i.stack.imgur.com/mTpOf.png" alt="Calculation worked"></p>
  
  <p>I've tried making the formula volatile by adding <code>Application.Volatile</code> to the function code, but it didn't change anything. Other methods to refresh the calculation, such as setting calculation to manual and then back to automatic, hidding "recalculate sheet", or just using <kbd>F9</kbd> or <kbd>Ctrl</kbd>+<kbd>F9</kbd> do not work, only re-entering the formula or <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>F9</kbd> will cause the function to recalculate properly.</p>
  
  <p>Changing one of the cells referenced in the if statement will not fix the problem, <strong>but</strong>, changing the cell referenced by the "CellIsFormula" function, does fix the problem. Every time the sheet is re-opened though, the error is back.</p>