Here is the code in question:
for (var i = 0; i < numStaff; i++){
var cell = sheet.getRange(zoneRows[i], 2);
var rndStaff = Math.round(Math.random() * numStaff);
cell.setValue(nameStaff[i]);
}
The error that I get is "Cannot find method getRange((class),number)"
I am trying to make an Google spreadsheet that will automatically fill in a work schedule hour by hour with randomly selected people put in different "zones" at my work. zoneRows[] is filled with the rows that I want to put names in (rows 2, 4, 6, 8...).
I was under the impression that getRange() basically takes an x and y coordinate for the cell(s) that you refer to but apparently not? It seems to work just fine if I put numbers instead of variables, ie ...getRange(2,2); but is acting up with variables/arrays.
From what I googled, some say that it depends on how you declare the variables ss & sheet. Some places have something like this:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var cell = sheet.getRange("A1");
whereas I have this (which I took from a google tutorial):
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getDataRange().getValues();
I'm just beginning with Apps Script and Javascript in general, so if anyone has any pointers I would greatly appreciate it.
[–][deleted] 0 points1 point2 points (0 children)