简体   繁体   中英

How to copy one range to end of another sheet

How do I copy one a Range from CopyFromMe tab, and paste to end of PasteAtEndOfMe tab in Google Sheets?

The function below has ERROR "The coordinates of the target range are outside the dimensions of the sheet." (unless I take out the +1)... but it does not paste anything. I've also tried other variations like,{contentsOnly:true});

   function CopyInfoToEndOfDifferentTab() {
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var copySheet = ss.getSheetByName('CopyFromMe');
      var pasteSheet = ss.getSheetByName('PasteAtEndOfMe');

      var source = copySheet.getRange('K8:P17')


    var destination = pasteSheet.getRange(pasteSheet.getLastRow()+1,1,source.getHeight(), source.getWidth());


    source.copyTo(destination);  

    }

I've tried this. Also tried this, from another thread... but still does nothing. Result is blank on PasteAtEndOfMe tab.

    function recordHistory() {
  var ss = SpreadsheetApp.getActive();
  var sheet = ss.getSheetByName("CopyFromMe");
  var source = sheet.getRange("K8:P17");
  var values = source.getValues();
  var sheet2 = ss.getSheetByName("PasteAtEndOfMe");
  values [0][0] = new Date();
  sheet2.getRange(sheet2.getLastRow()+1,1,values.length,values[0].length).setValues(values);
}

References:

Google Sheets Script - Copying data range from one sheet to another - whole range not copying

Make sure there is no data in any of the columns, even if invisible formula that renders nothing (like an if statement that renders “”)

This was adding content past Row 1000 so looked like it wasn't working on the visible test rows

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM