title: EPPLus Cell Formula #REF
body: <p>Hope someone can crack this issues with EPPLUS and Formulas.
  I'm getting an invalid #REF! when I try to assign a formula to a cell, yet the last row seems to accept the formula without a problem and does the calculations right.</p>
  
  <p>Here is what the logic looks like at the time of assignment of the Formula.  I am referencing data from another sheet.</p>
  
  <pre><code>        string formula1 = "";
          string formula2 = "";
  
          int uniqueTimeRow = 14;
          if (uniqueTimes.Rows.Count != 0)
          {
              foreach (DataRow row in uniqueTimes.Rows)
              {
                  if (row["ExecutionTime"].ToString() != "")
                  {
                      wsSummary.InsertRow(uniqueTimeRow, 1, uniqueTimeRow);
                      wsSummary.SetValue(uniqueTimeRow, 2, row["ExecutionTime"].ToString());
  
                      formula1 = "SUMIF(DataSummary[Strategy],$B" + uniqueTimeRow.ToString() + ",DataSummary[ExecQty])";
                      formula2 = "SUMIF(DataSummary[Strategy],$B" + uniqueTimeRow.ToString() + ",DataSummary[PrincipalAmount])";
  
                      wsSummary.Cells[uniqueTimeRow, 3].Formula = formula1;
                      wsSummary.Cells[uniqueTimeRow, 4].Formula = formula2;
  
                      uniqueTimeRow++;
                  }
              }
          }
  </code></pre>
  
  <p>This is what the result excel file looks like.</p>
  
  <p><a href="http://i.stack.imgur.com/Fudzl.jpg" rel="nofollow">Table Produced in Excel with the invalid #REF!</a></p>
  
  <p>This is the Formula Produced on the Last Cell:</p>
  
  <pre><code>=SUMIF(DataSummary[Strategy],$B28,DataSummary[ExecQty])
  =SUMIF(DataSummary[Strategy],$B28,DataSummary[PrincipalAmount])
  </code></pre>
  
  <p>If I copy these two formulas upwards this is what is produced as expected:</p>
  
  <pre><code>=SUMIF(DataSummary[Strategy],$B27,DataSummary[ExecQty])
  =SUMIF(DataSummary[Strategy],$B27,DataSummary[PrincipalAmount])
  </code></pre>
  
  <p>When it has the invalid #REF! this is what shows up in the formula:</p>
  
  <pre><code>=SUMIF(#REF!,$B27,#REF!)
  </code></pre>