title: How can Google Apps Script setFormula set a formula to sheet cell containing variables
body: <p>My plan is to calculate how many days between 2 given dates by using function <code>DATEDIF</code> in Google Spreadsheet and the function must be from Google Apps Script. I can get it by below.</p>
  <pre><code>sheet.getRange(x,10).setFormula('datedif(K32,L32,&quot;d&quot;)');
  </code></pre>
  <p>However, as the row is increasing by AppendRow whenever GAS calls spreadsheet so I tried to use variable x to get the last row. It makes me know where the target row is. My trouble is that I could not let setFormula to use variable as below, where <code>start</code> and <code>due</code> are A1Notation of the 2 given cells with date.</p>
  <pre><code>sheet.getRange(x,9).setFormula('datedif([start],[due],&quot;d&quot;)');
  </code></pre>
  <p>MY code is as below.</p>
  <pre><code>   var x = sheet.getLastRow();
     
     sheet.getRange(x,11).setValue(&quot;2020/05/20&quot;);
     sheet.getRange(x,12).setValue(&quot;2020/07/21&quot;);
      
     start = sheet.getRange(x,11).getA1Notation();
     due = sheet.getRange(x,12).getA1Notation();  
      
     
    sheet.getRange(x,9).setFormula('datedif([start],[due],&quot;d&quot;)');
  
    sheet.getRange(x,10).setFormula('datedif(K32,L32,&quot;d&quot;)');
  </code></pre>