I am trying to create a menu driven script that will insert a new row at the end of a sheet and copy down all formulas - with it auto increasing according to row index.
This is what I have so far but it copies down the EXACT formulas into the new row/cells but doesn't increase the row reference# like it would if I simply copied and pasted to new row.
EG, formula in B133 is =iferror(VLOOKUP(A37,DATA,5,0),"")
and when i run the script it copies it down to next new row/cell as =iferror(VLOOKUP(A37,DATA,5,0),"")
- when it should be =iferror(VLOOKUP(A38,DATA,5,0),"")
What I have written so far:
var ss = SpreadsheetApp.getActive();
function onOpen() {
var menu = [{name:"Add New Last Row", functionName:"addRow"}];
ss.addMenu("AM FUNCTIONS", 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);
var formulas = range.getFormulas();
var newRange = sh.getRange(lRow+1,1,1,lCol);
newRange.setFormulas(formulas);
}