I am attempting to create a script so that when a change is made in one spreadsheet the corresponding sheet with the same name in another spreadsheet receives the same change in the same place, and so I can put one lot of the script in each one and get two linked sheets that affect each other.
this is the code:
var targetID = 'ID of the sheet';
var targetSheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getName();
function onEdit(e){
var range = e.range;
var value = e.value;
var row = range.getRowIndex();
var column = range.getColumnIndex();
exportValue(row,column,value)
}
function exportValue(row,column,value) {
//(**this is the point where it breaks**)
var s = SpreadsheetApp.openById(targetID).getSheetByName(targetSheet);
var target = s.getRange(row, column);
target.setValue(value);
}
In my version i put in logs in between each line to see where it failed and it got to the line where i have put "this is the point where it breaks" and then didn't return anything after that.
Since attempting this I tried to open up the other file by just pulling out all of the variables but I couldn't get it to work.
the current error messages that it is going with are:
Cannot find function getSheetByName in object Sheet
Cannot find function openById in object Spreadsheet
I have spent so much time on this already and I feel like the answer is really simple but I would really appreciate any advice
Thanks in advance
:)
var targetID = 'ID of the sheet';
– Cooper