[英]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.我相信你的目标如下。
In this case, how about the following 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();
}
Cannot read property 'range' of undefined
occurs.当您直接运行脚本时,会出现Cannot read property 'range' of undefined
类的错误。 Please be careful about this.请注意这一点。srcRange.clearContent();
如果要在复制值后清除源范围,请使用srcRange.clearContent();
. .
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.