[英]Copy range of cells to another sheet
I have two tables on two sheets, I need to copy three chosen cells from first table and paste it in the table on the second sheet.我在两张纸上有两个表格,我需要从第一个表格中复制三个选定的单元格并将其粘贴到第二张表格中。
I recorded some actions and edited something there.我记录了一些动作并在那里编辑了一些东西。 So it copies range B9:D9 and pastes it into next empty row(var vv) on second sheet.
因此它复制范围 B9:D9 并将其粘贴到第二张纸上的下一个空行 (var vv) 中。 The best way I see it works is I choose one cell (for example B10) and it takes range B10:D10 and paste it in another sheet, I just can't find the info how to make this kind of copypaste.
我看到它工作的最好方法是我选择一个单元格(例如 B10),它采用 B10:D10 范围并将其粘贴到另一张纸上,我只是找不到如何制作这种复制粘贴的信息。
function copypaste() {
var vv = SpreadsheetApp.getActive().getSheetByName("Sheet2").getRange('M1').getValue();
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getCurrentCell().activate();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Sheet2'), true);
spreadsheet.getRange(vv).activate();
spreadsheet.getRange('\'Sheet1\'$B9:D9').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
spreadsheet.getActiveRangeList().setBackground(null);
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Sheet1'), true);
};
Try this:尝试这个:
function copypaste() {
const ss = SpreadsheetApp.getActive();
const sh2 = ss.getSheetByName("Sheet2");
const vs = sh2.getRange('B9:D9').getValues();
const sh1 = ss.getSheetByName("Sheet1");
sh1.getRange(sh1.getLastRow() + 1 , 2, vs.length,vs[0].length).setValues(vs);
}
Takes the values from Sheet2:B9:D9 and pastes them into Sheet1 next empty row column B to D从 Sheet2:B9:D9 中获取值并将它们粘贴到 Sheet1 的下一个空行列 B 到 D
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.