I believe your goal as follows.
- You want to copy the selected range to the last row of the same sheet using Google Apps Script.
For this, how about this answer?
Modification points:
- In the case of
var destRow = listToCopy.getLastRow()+1;
, the last row of the range of listToCopy
is retrieved.
- In your case, the last row of the sheet is required to be retrieved.
- The source range can be copied to the destination range as the start range like
getRange(destRow, 1)
.
- The 1st number of range is
1
.
spreadsheet
is not declared.
When above points are reflected to your script, it becomes as follows.
Modified script:
In order to use this script, please select the range and run the function of myFunction
. By this, the selected range is copied to the last row of the same sheet.
function myFunction() {
var sheet = SpreadsheetApp.getActiveSheet();
var listToCopy = sheet.getActiveRange();
var destRow = sheet.getLastRow() + 1;
listToCopy.copyTo(sheet.getRange(destRow, 1));
}
References: