Search code examples
google-apps-scriptcopy-paste

Copying data and pasting it to specific range


I am not being able to paste my data into specific cells in sheet2.

Like I have some data on sheet1 on the range of D:F and I want to paste it to the range of A:C on the last row. I need the code to adjust the range.


Solution

  • Try this:

    function myFunction() {
      var ss=SpreadsheetApp.getActive();
      var sh1=ss.getSheetByName('Sheet1');
      var sh2=ss.getSheetByName('Sheet2');
      var rg1=sh1.getRange(1,4,sh1.getLastRow(),3);
      rg1.copyTo(sh2.getRange(sh2.getLastRow()+1,1));
    }