The code below copies range and moves to next Spreadsheet in same workbook called \"Topup Required\".
I would like it to send this data to another spreadsheet inside
s.getRange(row, 1, 1, numColumns)
to the last row on the sheet of TOP UP NEEDED
in the Spreadsheet of sheet ID
, when the cell is edited.If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
Unfortunately, in the current stage, copyTo()
of Class range cannot be used for other Spreadsheet.
In this pattern, copyTo()
is used. So both the values and the cell format are copied.
When your script is modified, please modify as follows.
From:var targetSheet = ss.getSheetByName("TOP UP NEEDED");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).copyTo(target);
To:
var targetSS = SpreadsheetApp.openById("sheet ID");
s = SpreadsheetApp.getActiveSheet();
var tempSheet = s.copyTo(targetSS);
var targetSheet = targetSS.getSheetByName("TOP UP NEEDED");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
tempSheet.getRange(row, 1, 1, numColumns).copyTo(target);
targetSS.deleteSheet(tempSheet);
In this pattern, getValues()
and appendRow()
are used. So only the values are copied.
When your script is modified, please modify as follows.
From:var targetSheet = ss.getSheetByName("TOP UP NEEDED");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).copyTo(target);
To:
var targetSheet = SpreadsheetApp.openById("sheet ID").getSheetByName("TOP UP NEEDED");
var sourceValues = s.getRange(row, 1, 1, numColumns).getValues()[0];
targetSheet.appendRow(sourceValues);
In this modification, the simple trigger of onEdit()
cannot be used. An error occurs at openById()
. So please use the installable trigger of OnEdit event trigger. In this case, please modify the function name as follows.
From
function onEdit(event) {
To
function installedOnEdit(event) {
After this modification, please install the OnEdit event trigger to installedOnEdit as the installable trigger. By this, when the cell is edited, installedOnEdit
is run without the double executions. Please be careful this.
If I misunderstood your question and this was not the direction you want, I apologize.