1
votes

I have this code in google sheets:

function copy(row) {
  var value = sheet.getRange(row, 1).getValue();
  sheet.getRange(row, 3).setValue(value);
}

Then i change function onEdit

function onEdit(e){
  var range = e.range;
  copy(range.getRow());
}

Now this script copy some row, who we edit.

But i needed copy this row to other sheet. And if i make like this:

function copy(row) {
  var value = sheet.getRange(row, 1).getValue();
  var sheetTo = SpreadsheetApp.openById(ID).getSheetByName(NAME);
  sheetTo.getRange(row, 3).setValue(value);
}

It is not working. (If call function from editor it working well)

Please, help

2
Anastasia, welcome to SO! Could you please inform us what error (if any) you've received?Eugene
i dont know where i can see errors. always it show me like popup in editor, but now i have not anyАнастасия Норцова

2 Answers

2
votes

Please try to use sourceRange.copyTo(targetRange);instead setValue

0
votes

You cannot refer to an external sheet for the onEdit trigger. See here: google script openById : You do not have permission to perform that action