title: Apps Script: setting one formula for a whole column
body: <p>I'm working on an Apps Script project for Sheets and I don't know if it's because I just never really worked with Sheets or Excel, but I don't know how to set a formula for a whole column through code. </p>
  
  <pre><code>var cell = sheet.getRange([i], 2);
  var cell2 = sheet.getRange([i], 1);
  var inhoud = cell2.getValue();
  cell.setFormula("=(" + inhoud/86400000 + "DATE(1970,1,1)");
  </code></pre>
  
  <p>I want every B of a row to do something with the A of that same row. In the sheet self it's easy to just "drag the function down", to make it apply to every row, but I don't know how to get that to work in code as I can't use A2, for example, or A2:A30. Part of the problem may be that it's in a for loop: </p>
  
  <pre><code>var subsie = [];  
  
  for (i = 0; i &lt; subscriptions.length; i++) {
  
    var subscription = subscriptions[i];
  
    creationdate = subscription.creationTime;
  
    if (subscription.plan.planName == 'ANNUAL' &amp;&amp; subscription.renewalSettings.renewalType == 'AUTO_RENEW') {  
  
    subsie.push([creationdate, ' ', subscription.plan.planName]);
    Logger.log(subsie);
  
      var cell = sheet.getRange([i], 2);
      var cell2 = sheet.getRange([i], 1);
      var inhoud = cell2.getValue();
      cell.setFormula("=(A1:A100/86400000) + DATE(1970,1,1)");
  
    } }
  
    sheet.getRange(sheet.getLastRow()+1, 1, subsie.length, subsie[0].length).setValues(subsie);
  </code></pre>
  
  <p>The actual goal is to convert the epoch values of A into dates, which I tried in a lot of different ways but turned out to be more difficult than I expected. This was the only formula that seemed to work for my output, which was like this: <strong>1433235478178</strong>. How can I make this code work? Thanks in advance!</p>