I have the script below that gets me very close. I am hoping to copy "values" from "Sheet1 A1:AH5" to "Sheet5" adding 5 rows each time (and continue to append 5 more rows at the bottom of Sheet5 each time the script is triggered).
Any help is greatly appreciated.
(The script below pastes to same sheet and only copies the bottom of the first sheet instead of a range)
function copyRows(numRows = 5) {
const ss = SpreadsheetApp.getActive();
const sheet = ss.getActiveSheet();
const lRow = sheet.getLastRow();
const lCol = sheet.getLastColumn();
const maxRow = sheet.getMaxRows();
if (lRow === maxRow) sheet.appendRow(['']);
sheet.getRange(lRow - numRows + 1, 1, numRows, lCol)
.copyTo(sheet.getRange(lRow + 1, 1));
}
I believe your goal is as follows.
It seems that your script uses the same sheet. So, in order to achieve your goal, how about the following sample script?
function copyRows(numRows = 5) {
const ss = SpreadsheetApp.getActive();
const srcSheet = ss.getSheetByName("Sheet1");
const srcRange = srcSheet.getRange("A1:AH5");
const dstSheet = ss.getSheetByName("Sheet5");
const lastRow = dstSheet.getLastRow();
const dstRange = dstSheet.getRange(lastRow + 1, 1);
srcRange.copyTo(dstRange, {contentsOnly: true});
dstSheet.insertRows(lastRow + 6, numRows);
}
dstSheet.insertRows(lastRow + 6, numRows);
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.