Google Script - Copy Dynamic Range To New Spreadsheet
I'd appreciate some help on my first google script if possible. I'm trying to archive our daily processing log by copying and pasting them to the bottom of an end of day log sprea
Solution 1:
In data retrieved using ss.getRange('B7:J').getValues(), empty cells are included. So the length of retrieved data is larger than that of real data. 6467 and 6473 means the length of data array and the value from getMaxRows(), respectively.
And getMaxRows() retrieves the number of most bottom cell including empty cells. So in the case for using setValues(), data can be copied by using the length of data array for setValues as numRows of getRange (https://developers.google.com/apps-script/reference/spreadsheet/sheet#getRange(Integer,Integer,Integer,Integer) ).
The script is as follows.
function pasteprocessinglog() {
var sss = SpreadsheetApp.getActiveSpreadsheet();
var ss = sss.getSheetByName('Sheet_name');
var firstrow = 7; // 7th rowvar range = ss.getRange(firstrow, 2, ss.getLastRow() - firstrow + 1, 9);
vardata = range.getValues();
var tss = SpreadsheetApp.openById('URL');
var ts = tss.getSheetByName('Processing Log');
ts.getRange(ts.getLastRow() + 1, 2, data.length, 9).setValues(data);
}
If my understanding have mistaken, I'm sorry.
Post a Comment for "Google Script - Copy Dynamic Range To New Spreadsheet"