[英]Select cells(Ctrl+A) then Copy range and paste to another sheet's first empty row
I would like to copy a range from a sheet to another sheet's first empty row.我想将一个范围从一张纸复制到另一张纸的第一个空行。 But instead of copying the whole spreadseet i want to select the cells (like i do with CTRL+ A) and only the selected(ctrl+A) cells should be copied to another sheet's first row.
但是,我不想复制整个电子表格,而是要 select 单元格(就像我使用 CTRL+A 所做的那样)并且只有选定的(ctrl+A)单元格应该被复制到另一张工作表的第一行。 Here is a script that i found here in stackoverflow and it works but it only copy that range i give for example: sheet1:F1.H3.
这是我在stackoverflow中找到的一个脚本,它可以工作,但它只复制我给出的范围,例如:sheet1:F1.H3。 I want the script to find the cells like ctrl+ A does and then it copies to the other sheet's first empty row.
我希望脚本像 ctrl+ A 那样找到单元格,然后将其复制到另一张工作表的第一个空行。
Thank you so much for your help in advance.非常感谢您提前提供的帮助。
Here is the script:这是脚本:
function moveValuesOnly () {
var ss = SpreadsheetApp.getActiveSpreadsheet ();
var source = ss.getRange ("Sheet1!F1:H3");
var destSheet = ss.getSheetByName("Sheet2");
// Déterminer l'emplacement de la première ligne vide.
var destRange = destSheet.getRange(destSheet.getLastRow()+1,1);`enter code here`
source.copyTo (destRange, {contentsOnly: true});
source.clear ();
}
Using getDataRange() solved the issue.使用getDataRange()解决了这个问题。
As mentioned in the documentation:如文档中所述:
Returns a Range corresponding to the dimensions in which data is present.
返回与存在数据的维度相对应的范围。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.