简体   繁体   English

将单元格范围复制到另一个工作表

[英]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.

相关问题 Select 单元格(Ctrl+A)然后复制范围并粘贴到另一个工作表的第一个空行 - Select cells(Ctrl+A) then Copy range and paste to another sheet's first empty row 值增加时将单元格复制到另一个工作表 - Copy cells to another sheet when values increase Google Spreadsheets 脚本 - 如何将范围从一张纸复制到另一张纸,但不覆盖非空目标单元格 - Google Spreadsheets script - How to copy range from one sheet to another sheet, but without overwriting non-empty target cells 使用Google Appscript将范围复制到另一个工作表 - Copy range to another sheet with Google Appscript 用于将范围复制到另一张工作表的 Google 表格脚本 - Google Sheets script to copy a range to another sheet 将行的动态范围复制/追加到另一张工作表 - Copy/Append dynamic range of rows to another sheet 将Google文档中的范围复制到另一个工作表 - Copy range in google docs to another sheet 如何将一个范围复制到另一张纸的末尾 - How to copy one range to end of another sheet 将一系列值复制/粘贴到单独工作表上的下一组空单元格中 - Copy/Pasting a Range of Values into the Next Empty Set of Cells on a Separate Sheet 我有一个 GAS 脚本,可以将一系列单元格从一张表复制到另一张表,数据正确插入,但还添加了两个额外的空白行 - I have a GAS script to copy a range of cells from one sheet to another the data inserts correctly, but also adds two additional blank rows
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM