'Excel online Office-Scripts . Copy Range A1:J10 from worksheet2 and paste it on last row of column A of another sheet

I need some help I can do it in Excel VBA but can't find out how in Excel Online. I have the below example 1 work but it is not dynamic I need it to paste under the last row. If you can help please provide an example or edit the code and resend. Thank you.

//Example 1
  function main(workbook: ExcelScript.Workbook) {
    let data_sheet = workbook.getWorksheet("Data")
    let progr_sheet = workbook.getWorksheet("Programming");
// Paste to range A1 on progr_sheet from range A4:L19 on data_sheet
  progr_sheet.getRange('A4').copyFrom(data_sheet.getRange("A4:L19"), ExcelScript.RangeCopyType.all, false, false);
}

//Example 2 [Below doesn't work just and example of what I am trying to do.]
// function main(workbook: ExcelScript.Workbook) {
//   let data_sheet = workbook.getWorksheet("Data")
//   let progr_sheet = workbook.getWorksheet("Programming");
//   let myUsedRange = progr_sheet.getUsedRange();
//   let lastRow = myUsedRange.getRowCount();
//   console.log(lastRow) +1;
//   // Paste to range column A (lastRow) on progr_sheet from range A4:L19 on data_sheet
//   progr_sheet.getRange('A & lastRow').copyFrom(data_sheet.getRange("A4:L19"), ExcelScript.RangeCopyType.all, false, false);
//}


Solution 1:[1]

I think you got most of the way there. Your issue is this line

  progr_sheet.getRange('A & lastRow').copyFrom(data_sheet.getRange("A4:L19"), ExcelScript.RangeCopyType.all, false, false);

You can fix it by changing this part:

'A & lastRow'

To this:

'A' + lastRow

Just a note, with the way your code is currently structured, it overrides the last row of data in your Programming sheet. To copy the data to the next row, you just need to add 1 to your lastRow variable like so:

let lastRow = myUsedRange.getRowCount() + 1;

Also, for future questions like this, I would also add the Office Scripts tag so that people on there can view your future questions and assist you with them.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Brian Gonzalez