title: Application.WorksheetFunction.Sum within a loop
body: <p>I have this code which retrieves some data from a sql query and place it in an excel Sheet:</p>
  
  <pre><code>   I = 4
   Do While Not rs.EOF
    I = I + 1
    Sheet1.Range("A" &amp; I).Value = rs(0)
    Sheet1.Range("B" &amp; I).Value = rs(1)
    Sheet1.Range("C" &amp; I).Value = rs(2)
    Sheet1.Range("D" &amp; I).Value = rs(3)
    Sheet1.Range("E" &amp; I).Value = rs(4)
    Sheet1.Range("F" &amp; I).Value = rs(5)
    Sheet1.Range("G" &amp; I).Value = rs(6)
    Sheet1.Range("H" &amp; I).Value = rs(7)
    Sheet1.Range("I" &amp; I).Value = rs(8)
    Sheet1.Range("J" &amp; I).Value = rs(9)
    Sheet1.Range("K" &amp; I).Value = rs(10)
    Sheet1.Range("L" &amp; I).Value = rs(11)
    Sheet1.Range("M" &amp; I).Value = rs(12)
    Sheet1.Range("N" &amp; I).Value = rs(13)
    Sheet1.Range("O" &amp; I).Value = rs(14)
    Sheet1.Range("P" &amp; I).Value = rs(15)
    Sheet1.Range("Q" &amp; I).Value = Application.WorksheetFunction.Sum(Sheet1.Range("E" &amp; I), Sheet1.Range("P" &amp; I))
    'Sheet1.Range("Q" &amp; I).Value = Sheet1.Range("E" &amp; I).Value + Sheet1.Range("F" &amp; I).Value + Sheet1.Range("G" &amp; I).Value + Sheet1.Range("H" &amp; I).Value
    rs.MoveNext
   Loop
  </code></pre>
  
  <p>Now, I'm trying to sum a range of columns from col "E" to col "P" but it didn't work, it just sum those cells only ("E" &amp; I and "P" &amp; I), not the range.</p>
  
  <p>Any help please?</p>