General Discussion

Daniel Turner
Daniel Turner
6,738 Points

I'm having trouble with this for loop. can someone help?

function linkTotals() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; var newSheet = ss.getSheets()[2]; var name = newSheet.getSheetName();

/var oldS = sheet.getRange("D4:E5"); var newS = "'" + name + "'!C3"; var finalS = oldS.getFormula() + " + " + newS; oldS.setFormula(finalS);/

var oldS = sheet.getRange("D4:D5"); var lc = oldS.getLastColumn(); var lr = oldS.getLastRow();

for(var i=0; i<lc; i++) { for(var j=0; j<lr; j++) { var newS = "'" + name + "'!D4"; var finalS = oldS.getFormula() + " + " + newS; oldS.setFormula(finalS); } }
}