Search code examples
google-sheetsgoogle-apps-scriptgoogle-sheets-formula

SpreadsheetApp how to use variable inside formula


I want to be able to put my variable row into the

.setValue("=SUM(B54:BA54)")

Actually I need the value of row to replace B54:B54. I'm looking for something like

.setValue("=SUM(B+row+:BA+row)")

So if row = 50 the setValue will put =SUM(B50:BA50) in the cell

var text3 = result3.getResponseText();
var row = parseInt(text3);
activeSheet.getRange(row+3,55).setValue("=SUM(B54:BA54)");

Solution

  • var text3 = result3.getResponseText();
    var row = parseInt(text3);
    activeSheet.getRange(row+3,55).setValue("=SUM(B" + row + ":BA" + row + ")");
    

    using concatenation should work like you want it.