-1

My question is about developing a script that will iterate through all google sheets (multiple files) in a folder, capture the data from each sheet file that is on a data consolidation sheet named getdata, and append it to a master sheet named Advisory Master.

R. Wurth
  • 11
  • 1
  • 2
    Welcome to Stack Overflow! Please read [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and also [what have you tried](http://mattgemmell.com/what-have-you-tried/). – Jason Aller Feb 04 '18 at 20:51

1 Answers1

6

Iterating throught all of the Sheets in a Folder

This will iterate through all of the sheets in a folder getting the File Name and the Sheet Name for each sheet and appending it to a sheet named filesSheet.

function iterateSheets() {
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getSheetByName('filesSheet');
  sh.clear();
  var folder=DriveApp.getFolderById('id');//replace id with actual id of folder
  var files=folder.getFilesByType(MimeType.GOOGLE_SHEETS);
  while(files.hasNext()){
    var file=files.next();
    var ts=SpreadsheetApp.openById(file.getId());
    var allShts=ts.getSheets();
    for(var i=0;i<allShts.length;i++) {
      sh.appendRow([file.getName(),allShts[i].getName()]);
    }
  }
}

With this as a starting point you should be able to consolidate all of your data.

Cooper
  • 59,616
  • 6
  • 23
  • 54