So very much piecing together and learning google scripts and 1st challenge is to do the following: Several subsheets completed by agents who will use a script to collate onto a master sheet any that are not already on there.
Script will need to: Check if data in the subsheet table has been been already copied to master sheet (look at a cell for a 0 or 1). If 0 copy that to the last row of the master sheet. I've used a countifs formula to populate the 0 or 1 on each sub sheet.
I've managed to build the script to do this from one sheet to another in the same workbook but get an error message when trying to do so in different workbooks. Also found a clone script that does copy the data (whole page) to the master but overwrites and not last row and also ignores the 0 and 1 rule.
Looked across many similar questions and online and struggling to see anyone with this same need and fix?
Codes: Copy all the new data to another sheet in same workbook from the last row: /**
Retrieves all the rows in the active spreadsheet that contain Yes
in the Include column and copies them to the Report sheet. */
function copyRows2() {
var sSheet = SpreadsheetApp.getActiveSpreadsheet();
var srcSheet = sSheet.getSheetByName("Import2");
var tarSheet = sSheet.getSheetByName("Report");
var lastRow = srcSheet.getLastRow();
for (var i = 2; i <= lastRow; i++) { var cell = srcSheet.getRange("C" + i); var val = cell.getValue(); if (val == "0") {
var srcRange = srcSheet.getRange("A" + i + ":D" + i);
var tarRow = tarSheet.getLastRow(); var tarRange = tarSheet.getRange("A" + (tarRow+1) + ":D" + (tarRow+1));
srcRange.setValues(tarRange); } } };`
Clone whole Sheet from workbook A to workbook B:
function cloneGoogleSheet(ssA, ssB) {
// source doc
var sss = SpreadsheetApp.openById('Source Workbook ID');
// source sheet
var ss = sss.getSheetByName('Import');
// Get full range of data
var SRange = ss.getDataRange();
// get A1 notation identifying the range
var A1Range = SRange.getA1Notation();
// get the data values in range
var SData = SRange.getValues();
// target spreadsheet
var tss = SpreadsheetApp.openById('Target WorkbookID');
// target sheet
var ts = tss.getSheetByName('Master2');
// set the target range to the values of the source data
ts.getRange(A1Range).setValues(SData);
};