Google Script To Copy From Each Sheet In Folder To A Master Sheet In Folder Based?
I have a folder named 'TEST FOLDER' I have two spreadsheets, TEST1 AND TEST2, I also have a spreadsheet called MASTER. I want to have a script in the MASTER Spreadsheet which will
Solution 1:
I change a bit the code and this one must work. Please adapt depending your file structure
function getDataToMaster() {
var folder = DriveApp.getFolderById("IdOfFolder"); //Define id of foldervar contents = folder.getFiles();
var file;
vardata;
var sheetMaster = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; //first sheet of the file, change by getSheetByName("NAME") if you wantwhile(contents.hasNext()){
file = contents.next();
if (file.getMimeType() == "application/vnd.google-apps.spreadsheet") {
var sheet = SpreadsheetApp.openById(file.getId()).getSheets()[0];//first sheet of the file, change by getSheetByName("NAME") if you wantvar startRow = 2;
vardata = sheet.getDataRange().getValues();
var colToCheck = 6;
for(var j = 1; j < data.length;j++){
if(data[j][colToCheck-1] != "copied"){
sheetMaster.appendRow(data[j]);
sheet.getRange((j+1), colToCheck).setValue("copied");
SpreadsheetApp.flush();
}
}
}
}
}
Stéphane
Post a Comment for "Google Script To Copy From Each Sheet In Folder To A Master Sheet In Folder Based?"