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