Home > database >  Using getRange to return entire column of data
Using getRange to return entire column of data

Time:10-14

Code is as follows:

    function AdjAvail() {


var ss = SpreadsheetApp.getActiveSpreadsheet();
var masterSheet =ss.getSheetByName("Master");
var masterAvail = ss.getSheetByName("Unique Territories - Availability");

var apptTerr = masterSheet.getRange(6,2).getValue();
var apptTime = masterSheet.getRange(9,5).getValue();

var lastCol = masterAvail.getLastColumn();
var lastRow = masterAvail.getLastRow();

var lookupTime = masterAvail.getRange(1,1,1,lastCol).getValues()[0];
var lookupTerr = masterAvail.getRange(1,1,lastRow,1).getValues();

var timeIndex = lookupTime.indexOf(apptTime) 4;
// var terrIndex = lookupTerr.indexof(apptTerr) 4;


Logger.log(lookupTerr);

Directly below works perfectly and returns an entire row of data:

var lookupTime = masterAvail.getRange(1,1,1,lastCol).getValues()[0];

The next line below returns all data I want, but inside closed brackets.

var lookupTerr = masterAvail.getRange(1,1,lastRow,1).getValues();

Or if I adjust to the following, it only returns the top-left cell:

var lookupTerr = masterAvail.getRange(1,1,lastRow,1).getValues()[0];

I need to return the entire array so I can run the function below:

var terrIndex = lookupTerr.indexof(apptTerr) 4;

I'm sure it's something simple, but I'm lost, any help would be appreciated. Thank you.

CodePudding user response:

Flatten the 2D-array obtained by .getValues() with flat():

var lookupTerr = masterAvail.getRange(1,1,lastRow,1).getValues().flat();

and see if that helps?

  • Related