Home > Net >  Iterating over a number of spread sheets in a folder and I want to pull last 3 columns from each
Iterating over a number of spread sheets in a folder and I want to pull last 3 columns from each

Time:01-05

I am trying to find a solution to pull the data of a number of sheets into a single master doc. I am only interested in the last three columns of each sheet, however the sheets do not all have the same number of columns.

    function getDataFromSpreadsheet(ssID) {

  var ss = SpreadsheetApp.openById(ssID);
  var ws = ss.getSheets()[0];
  var data = ws.getRange("A1:W"   ws.getLastRow()).getValues();
return data;

}

I assume I can do something with getrow.length()[-3] but I am having no luck at all getting it to work.

CodePudding user response:

Change your range

from:

var data = ws.getRange("A1:W"   ws.getLastRow()).getValues();

to:

var data = ws.getRange(1, ws.getLastColumn()-2, ws.getLastRow(), 3).getValues();

Example:

Sheet1:

enter image description here

Output:

enter image description here

References:

  •  Tags:  
  • Related