Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select entire row as range (indefinite number of columns)

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!!

like image 757
swimminggymnast Avatar asked Aug 09 '18 00:08

swimminggymnast


1 Answers

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)")
like image 171
Rubén Avatar answered Oct 23 '22 03:10

Rubén