title: How to use for to sum a range in google app script?
body: <p>I want create a simple custom sum formula in google Spreadsheets using google app Script.</p>
  
  <pre><code> function somaDias(range, days) {
     var sum = 0;
  
     for(i=0; i&lt;days; i++){
       sum = sum + range[i];
    }
  
  
      return soma;
      }
  </code></pre>
  
  <p>I will use this function in a report that has a column with monetary values for each day of the month. The idea is to select the whole column of values, pass it as a range and them sum this values up to a day of the month. I know there is something wrong with </p>
  
  <pre><code>  sum = sum + range[i];
  </code></pre>
  
  <p>because, when I test it with a column that has only 1... the return is "0111111"</p>
  
  <p>=somaDias(C9:C15;6) // should return 6, but it returns 0111111</p>
  
  <p>I don´t want to use =sum(), because the range changes according to the day. I want to pass as the range the 30 days of the month and then pass the number of days I want to sum. If I used sum, I would have to reselect the range everyday....</p>
  
  <p>What I´m doing wrong?</p>