As a workaround for Apps Script triggers not being fired by automatic sheet updates, you need to use IMPORTRANGE to import your data into a dummy sheet. IMPORTRANGE will detect also through automatic sheet update and simultaneously it is able to fire an onEdit trigger.
Do the following:
Delete all empty rows in MASTER spreadsheet
Create a dummy spreadsheet and import into it the contents of MASTER spreadsheet
with a formula:
- From the dummy sheet, open the script editor and insert the following code:
function changed(e) {
var masterSheet = SpreadsheetApp.getActive().getSheetByName("Sheet1");
if(PropertiesService.getScriptProperties().getKeys().length==0){
PropertiesService.getScriptProperties().setProperty('startRow', 5);
}
var startRow=PropertiesService.getScriptProperties().getProperty('startRow');
var lastRow=masterSheet.getLastRow();
var numRows=lastRow-startRow+1;
var startCol=1;
var numCols=6;
var values=masterSheet.getRange(startRow,startCol,numRows,numCols).getValues();
var FBsheet=SpreadsheetApp.openById('1SzBx5Q9rrlcLGSqD8y5eFE5TX304LfZ7D9mxxrHhfKw').getSheetByName('Sheet1');
var ATsheet=SpreadsheetApp.openById('1IRD8wT5Kmx7h_xP807f4ibWRn8g98RjA-dJXxADXAl0').getSheetByName('Sheet1');
FBsheet.getRange(FBsheet.getLastRow()+1,startCol, numRows, numCols).setValues(values);
var ATlastRow=ATsheet.getLastRow();
for(var i=0;i<numRows;i++){
Logger.log(values[i][1]);
ATsheet.getRange(ATlastRow+1+i,1, 1, 1).setValue(values[i][1]);
ATsheet.getRange(ATlastRow+1+i,2, 1, 1).setValue(values[i][0]);
ATsheet.getRange(ATlastRow+1+i,3, 1, 1).setValue(values[i][3]);
ATsheet.getRange(ATlastRow+1+i,4, 1, 1).setValue(values[i][2]);
ATsheet.getRange(ATlastRow+1+i,5, 1, 1).setValue(values[i][5]);
ATsheet.getRange(ATlastRow+1+i,6, 1, 1).setValue(values[i][4]);
}
PropertiesService.getScriptProperties().setProperty('startRow', lastRow+1);
}
- Attach to the script an
onEdit
trigger
- Run the script once manually, it is normal that it will throw you an error
- Now the script will run automatically each time data update takes place in
MASTER spreadsheet
.
Make sure you change all spreadsheetIDs and sheet names with your
values.