Google script (copy row to other sheet onEdit)

2019-08-04 02:16发布

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条回答
叼着烟拽天下
2楼-- · 2019-08-04 02:46

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

查看更多
神经病院院长
3楼-- · 2019-08-04 02:48

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

查看更多
登录 后发表回答