I'm a beginner at Google Apps Script and want to select an entire row after a certain cell to use in a formula.
function setUpSheet()
{
var infoRange = SpreadsheetApp.getActiveSpreadsheet().getRange("A1:D1");
infoRange.setValues([ ["Last", "First", "Username", "Total"] ]);
var cells = SpreadsheetApp.getActiveSpreadsheet().getRange("D2:D");
var tabRange = ???
cells.setFormula(["=SUM(tabRange)"]);
}
I want to set the formula in the last line to every column following the 'Total' column. For example, I would like D2 to have the sum E2+F2+G2+.....+ an indefinite number of cells in the second row. How would I create a range from E2 to the end of the row? Any help is so much appreciated!!
Use number:number
to select all the columns on row number
.
To include only columns from column E2
to the last column use E2:2
.
Regarding setFormula(formula), the argument should be a string, so instead of
cells.setFormula(["=SUM(tabRange)"])
use
cells.setFormula("=SUM(E2:2)")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With