For some reason this code doesn't do the copy. What am I doing wrong please?
var targetSheetName="My Target"
var targetSheet=SpreadsheetApp.getActiveSpreadsheet().getSheetByName(targetSheetName);
var sourceRange = SpreadsheetApp.getActiveSheet().getDataRange();
sourceRange.copyTo(targetSheet.getRange(targetSheet.getMaxRows()+1, 1));
I've also tried var sourceRange = SpreadsheetApp.getActiveSheet().getDataRange().getRow(); to assign the data, as it's unclear to me what range of data getDataRange() is getting, so I thought maybe it's getting the entire active sheet, and therefore possibly failing when it tries to copy one row. Bottom line is I tried a variety of things and nothing seems to work.
I've looked at example after example after example and all of them are so different from each other I keep running into roadblocks trying to convert what they have into what I need. The above is what I finally settled on and tweaked for my use, but I'm still stuck.
Thanks in advance.
getRange(targetSheet.getMaxRows()+1,1)
will fail because it is trying to get a row that doesn't and can't exist. This is easily corrected, but first: what exactly are you wanting to copy over? (all the rows? One row? If one, which one - the last one? Are you happy to just copy values over, or do you need to copy formulae and/or formatting as well?) – AdamL