title: How can I use C# Excel "Microsoft.Office.Interop.Excel", to count the amount of not empty cells in a one columns
body: <p>So I have this spreadsheet, it has Fname, Lname, Pnumber, Email, Cid. Cid is the only really important one, the rest are optional technically. </p>
  
  <p>So instead of just doing a loop to see when the cell values starts being null, I know you can use the</p>
  
  <p>WorksheetFunction.CountA(some 30 different variable that I do not understand but are optional too); </p>
  
  <p>to get the actual numbers of filled cells, and it is instant. I have no idea how to do this.</p>
  
  <p>This is what I'm going to do viva looping, but I know the CountA() function can do it in one line.</p>
  
  <pre><code>int i = 1;
  while (i &lt;= 200)
  {
      cell = (Microsoft.Office.Interop.Excel.Range)worksheet.Cells[i, 5];
      if (cell.Value2 &gt; 0)
      {i++;}
      else
      {break;}
  }
  int totalCol = i;
  </code></pre>
  
  <hr>
  
  <p>Ok, this is what I have now, thanks everyone.</p>
  
  <pre><code>var cell = (Microsoft.Office.Interop.Excel.Range)worksheet.Cells[1, 1];
      cell.Formula = "=CountA(E1:E200)";
                      double totalCells = (cell.Value2) -1;
  </code></pre>