I'm trying to write a piece of code that syncronize two sheets (the motivation behind it is here). I got this code from a SOF previous answer:
var sourceSpreadsheetID = SPREADSHEET.getId();
var sourceWorksheetName = "myData";
var destinationSpreadsheetID = "0AmEr9uNtZwnNdDFKMTVlbmZYZ3ZyOWM0aXpZS2twM1Z";
var destinationWorksheetName = "myData2";
function importData() {
var thisSpreadsheet = SpreadsheetApp.openById(sourceSpreadsheetID);
var thisWorksheet = thisSpreadsheet.getSheetByName(sourceWorksheetName);
var thisData = thisWorksheet.getDataRange();
var toSpreadsheet = SpreadsheetApp.openById(destinationSpreadsheetID);
var toWorksheet = toSpreadsheet.getSheetByName(destinationWorksheetName);
var toRange = toWorksheet.getRange(1, 1, thisData.getNumRows(),thisData.getNumColumns());
toRange.setValues(thisData.getValues());
}
function onEdit(){
importData();
}
But when I open the sheet and edit it, nothing happens. Why?
PS - As I pointed before, I've already ask a similar question. But I think this is another question, because I'm not looking for the same answer from the previous question (How to make 2 sheets sync?) but a more specific question: what is preventing this code -- this solution -- of work?