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:
Output:


