title: Google Apps Script to Iterate through a list of Spreadsheet ID's and copy range to a master file
body: <p>I have a folder in my drive where I create a folder (based on a template structure) for each new client. I need to extract information from one file in particular from each of their folders. I have the Spreadsheet IDs in a list, and I know the sheet name, I am just not sure how to create a loop to go through each file and append it to a master file.</p>
  
  <p>I found a script recently <a href="https://stackoverflow.com/questions/32556518/google-script-to-copy-from-each-sheet-in-folder-to-a-master-sheet-in-folder-base">here</a> which would do the trick, but it assumes that all the spreadsheets are in one folder:</p>
  
  <pre><code>function getDataToMaster2() {
      var comp = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("System_Control").getRange("d7").getValue();
    var folder = DriveApp.getFolderById(comp); //Define id of folder
    var contents = folder.getFiles();
    var file; 
    var data;
    var sheetMaster = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form_Responses"); //first sheet of the file, change by getSheetByName("NAME") if you want
    while(contents.hasNext()){  
      file = contents.next();
      if (file.getMimeType() == "application/vnd.google-apps.spreadsheet") {
        var sheet = SpreadsheetApp.openById(file.getId()).getSheetByName("Form_Responses");//first sheet of the file, change by getSheetByName("NAME") if you want
        var startRow = 2; 
        var data = sheet.getDataRange().getValues();
        var colToCheck = 14;
        for(var j = 1; j &lt; data.length;j++){
          if(data[j][colToCheck-1] != "copied"){
            sheetMaster.appendRow(data[j]);
            sheet.getRange((j+1), colToCheck).setValue("copied");
            SpreadsheetApp.flush();
          }
        }
      } 
    }
  }
  </code></pre>