title: google script for inserting a row and copying formulas down
body: <p>I'm new here and struggling with the wonderful world of google script at the mo so could realy do with your help.</p>
  
  <p>I have a google sheets doc and columns c to z all contain formulas that I have copied down the whole sheet,</p>
  
  <p>the problem is I need to be able to insert a row and have the formula in the row above it copy down.
  I found a code online that will add a new last row and copy the formulas but I need one that I can select a row, click the script and it insert a new rowwith the formulas copied down,</p>
  
  <p>can anyone give me help on the script I need to do this?</p>
  
  <p>here is the script I have which does exactly what I want but for the last row not the selected row.</p>
  
  <pre><code>function onOpen() {
    var menu = [{name:"Add New Last Row", functionName:"addRow"}];
    ss.addMenu("Extra", menu);
  }
  
  function addRow() {
    var sh = ss.getActiveSheet(), lRow = sh.getLastRow(); 
    var lCol = sh.getLastColumn(), range = sh.getRange(lRow,1,1,lCol);
    sh.insertRowsAfter(lRow, 1);
    range.copyTo(sh.getRange(lRow+1, 1, 1, lCol), {contentsOnly:false});
  }
  </code></pre>
  
  <p>if someone can tel me how to fix this I would be very greatful</p>
  
  <p>Thanks</p>
  
  <p>Tony</p>