Reputation: 2107
In this script I can copy column A from row 1 to the last row containing values and send it to column H of another worksheet.
But I can't adjust to copy column A, B, C and D and send them at the same time to the other worksheet in Column H, I, J, K.
What do I need to do to make it possible to copy 4 columns at once without having to use formulas within the spreadsheet?
function TestesGerais() {
var sss = SpreadsheetApp.openById('AAAAAAA');
var ss = sss.getSheetByName('Sheet13');
var range = ss.getRange(1,1,ss.getLastRow(),1);
var data = range.getValues();
var tss = SpreadsheetApp.openById('BBBBBBBB');
var ts = tss.getSheetByName('Sheet14');
ts.getRange(1,8, data.length, data[0].length).setValues(data);
}
Note: Thanks @Cooper (https://stackoverflow.com/users/7215091/cooper) for alerting me to an error in my script and my question, already details updated.
Upvotes: 0
Views: 336
Reputation: 64032
Try this:
function TestesGerais() {
var sss = SpreadsheetApp.openById('AAAAAAA');
var ss = sss.getSheetByName('Sheet13');
var range = ss.getRange(1,1,ss.getLastRow(),4);//Simple change made the last one a four. This is something you should be able to do for yourself.
var data = range.getValues();
var tss = SpreadsheetApp.openById('BBBBBBBB');
var ts = tss.getSheetByName('Sheet14');
ts.getRange(1,8, data.length, data[0].length).setValues(data);
}
Upvotes: 2