简体   繁体   English

从范围复制单元格值并将其粘贴到另一个工作表的单行中

[英]To copy Cell values from a range and paste it in a single row of another sheet

Wanted to accomplish below mentioned task, Having 2 Sheets(Sheet1 and Sheet 2) On clicking the Checkbox on Sheet 1:J1, data present in the table form on the Sheet 1 should get pasted in the single row of Sheet2 For eg Product 1 data (P1) to the Product 1 Column, Product 2 data (P2) to the Product 2 Column and so on... For every new submit, new data to be recorded on the next row of Sheet2.想要完成下面提到的任务,拥有 2 张工作表(工作表 1 和工作表 2)单击工作表 1:J1 上的复选框时,工作表 1 上的表格中的数据应粘贴在工作表 2 的单行中,例如产品 1 数据(P1) 到产品 1 列,产品 2 数据 (P2) 到产品 2 列等等......对于每个新提交,新数据将记录在 Sheet2 的下一行。 SS link: https://docs.google.com/spreadsheets/d/1tmnDOMyupjeO8d65qHQsxb5KrrKeq7pMYIE8h2VmEJ4/edit?usp=sharing SS 链接: https ://docs.google.com/spreadsheets/d/1tmnDOMyupjeO8d65qHQsxb5KrrKeq7pMYIE8h2VmEJ4/edit?usp=sharing

Thanks in advance提前致谢

I believe your goal is as follows.我相信你的目标如下。

  • When a checkbox of "H1" of "Sheet1" is checked, you want to copy the values from the cells "A3:G6" to the columns "B" to "AC" in one row of "Sheet2".当检查“ Sheet1”的“ H1”的复选框时,您想将“ A3:G6”单元格的值复制到“ Sheet2”的一行中的列“ B”列。
  • And, you want to copy "B1" and "B10" of "Sheet1" to the columns "A" and "AD" of "Sheet2".并且,您要将“Sheet1”的“B1”和“B10”复制到“Sheet2”的“A”和“AD”列。
  • In your Spreadsheet, there are no merged cells.在您的电子表格中,没有合并的单元格。

In this case, how about the following sample script?在这种情况下,下面的示例脚本怎么样?

Sample script:示例脚本:

function onEdit(e) {
  const range = e.range;
  const sheet = range.getSheet();
  if (sheet.getSheetName() != "Sheet1" || range.getA1Notation() != "H1" || !range.isChecked()) return;
  const srcRange = sheet.getRange("A3:G6");
  const [[b1], , , , , , , , , [b10]] = sheet.getRange("B1:B10").getValues();
  const values = [b1, ...srcRange.getValues().flat(), b10];
  const dstSheet = e.source.getSheetByName("Sheet2");
  dstSheet.appendRow(values);
  range.uncheck();
  // srcRange.clearContent();
}
  • This script is automatically run with the simple trigger of OnEdit trigger.该脚本使用 OnEdit 触发器的简单触发器自动运行。 So, when you use this script, please check the checkbox of "H1" of "Sheet1".因此,当您使用此脚本时,请选中“Sheet1”的“H1”复选框。 By this, the script is run.这样,脚本就运行了。 When you directly run the script, an error like Cannot read property 'range' of undefined occurs.当您直接运行脚本时,会出现Cannot read property 'range' of undefined类的错误。 Please be careful about this.请注意这一点。
  • If you want to clear the source range after the values were copied, please use srcRange.clearContent();如果要在复制值后清除源范围,请使用srcRange.clearContent(); . .

Note:笔记:

  • This sample script is for your sample Spreadsheet.此示例脚本适用于您的示例电子表格。 So, when you changed your Spreadsheet, this script might not be able to be used.因此,当您更改电子表格时,此脚本可能无法使用。 Please be careful about this.请注意这一点。

Reference:参考:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 复制单元格中的值并将值粘贴到同一工作表中的另一个单元格 - Copy values from cell and paste the values onto another cell in the same sheet 复制一个范围并仅将具有值和图像的行粘贴到另一个工作表中下一个空白行的谷歌工作表中? - Copy a range and paste only rows with values & images into another sheet at the next blank row in the google sheets? 复制一个范围并仅将带有值的行粘贴到下一个空白行的另一个工作表中? - Copy a range and paste only rows with values into another sheet at the next blank row? 需要将行从sheet1复制到sheet2,并将单元格值粘贴到sheet2中具有匹配列值的行上 - Need to copy row from sheet1 to sheet2 and paste the cell values on a row in sheet2 with a matching column value 如果单元格值 = x,则有效地将行复制并粘贴到另一个工作表 - Efficiently Copy and Paste Row to Another Sheet if Cell Value = x 使用 AppScript 将行从一张表复制粘贴到另一张比较单元格值以避免重复 - Copy-Paste rows from one sheet to another comparing cell values to avoid duplicates using AppScript 将单元格值从一张纸复制并粘贴到另一张onEdit - copy and paste cell value from one sheet to another onEdit 将一个工作表中命名范围的单元格值复制到另一工作表中另一个命名范围的相同单元格地址 - copy cell values of named range in one sheet to same cell address of another named range in another sheet 从最后一行复制特定的列数据并粘贴到另一个工作表 - Copy specific Columns data from Last Row and paste to another sheet 如何将范围从母版表复制到另一张表的最后一行(另一张表名称= Mastersheet Z1中的单元格值) - How to copy a range from a mastersheet to the last row of another sheet (Another sheet name = cell value in Mastersheet Z1)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM