I need to copy this range A1 : BU17 to another sheet in the same spreadsheet in the next rows avaible. I tried to use this:
function Copy() {
var sss = SpreadsheetApp.openById('x'); //replace with source ID
var ss = sss.getSheetByName('Analysing'); //replace with source Sheet tab name
var range = ss.getRange('A1:BU17'); //assign the range you want to copy
var data = range.getValues();
var tss = SpreadsheetApp.openById('x'); //replace with destination ID
var ts = tss.getSheetByName('Archive'); //replace with destination Sheet tab name
ts.getRange(ts.getLastRow()+1, 1, data.length, data[0].length).setValues(data);
}
I found this searching inside stackoverflow. It does copy my rows to the next one avaible but not the format too so is a total mess when i'm using it. Ofc "X" is the id i know. Thank you in advance if someone can help me.
How about this modification? Please think of this as one of several answers.
You can use copyTo()
. But there are some limitations.
copyTo()
of Class Range can copy both the formats and values to a sheet and a range in the same spreadsheet. copyTo()
of Class Range cannot copy the data to a range and a sheet in other spreadsheet. copyTo()
of Class Sheet can copy a sheet to other spreadsheet. copyTo()
of Class Sheet cannot copy a range. By reflecting them, your script can be modified as follows.
copyTo()
of Class Sheet. copyTo()
of Class Range. copyTo()
of Class Sheet. function Copy() {
var sss = SpreadsheetApp.openById('x'); //replace with source ID
var ss = sss.getSheetByName('Analysing'); //replace with source Sheet tab name
var srcrange = ss.getRange('A1:BU17'); //assign the range you want to copy
var tss = SpreadsheetApp.openById('x'); //replace with destination ID
var ts = tss.getSheetByName('Archive'); //replace with destination Sheet tab name
var dstrange = ts.getRange(ts.getLastRow()+1, 1, srcrange.getHeight(), srcrange.getWidth());
var dstSS = dstrange.getSheet().getParent();
var copiedsheet = srcrange.getSheet().copyTo(dstSS);
copiedsheet.getRange(srcrange.getA1Notation()).copyTo(dstrange);
dstSS.deleteSheet(copiedsheet);
}
If I misunderstand your question, I'm sorry.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.