I use this formula to copy values from one column to another spreadsheet column:
function SheetToSheet() {
var sss = SpreadsheetApp.openById('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA');
var ss = sss.getSheetByName('Sheet 1');
var range = ss.getRange(12,1,ss.getMaxRows()+1-12,1);
var data = range.getValues();
var tss = SpreadsheetApp.openById('BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB');
var ts = tss.getSheetByName('Sheet 2');
ts.getRange(12,1, data.length, data[0].length).setValues(data);
}
In this case where I want to collect the values from the line 12
, use ss.getMaxRows()+1-12
in case it is necessary to add rows in the other spreadsheet, it will add literally only as many rows as necessary.
Result:
Add Row 11, 12, 13, 14 and 15
Add Values in Row 12, 13, 14 and 15
If I use getlastrow()
, several more unnecessary lines are added:
If I use the getMaxRows()
without calculating +1-NumberOfRows
, it always copies more lines than necessary too:
Is there a fixed model that is not always necessary to place the calc +1-NumberOfRows
? I am afraid to forget to change the value for the calculation and to add erroneous amounts of lines.