[英]copy and paste cell value from one sheet to another onEdit
I wrote a google script to create and paste the values from a cell in one sheet to another (same spreadsheet). 我写了一个Google脚本来创建值并将其值从一个工作表中的单元格粘贴到另一个工作表中(相同的电子表格)。 The code consists of following two steps: 该代码包括以下两个步骤:
(works): If a cell of specific columns of one sheet are edited, then the next adjacent cell gets a value based on the edit. (有效):如果编辑了一张纸中特定列的单元格,则下一个相邻的单元格将基于该编辑获得一个值。
(does not work): Paste the new value of the adjacent cell into the cell of the next empty row (1st column) in the second sheet. (无效):将相邻单元格的新值粘贴到第二张工作表中下一个空行(第一列)的单元格中。
The code below is what I have tried so far, but the value does not appear on the second sheet. 到目前为止,下面的代码是我尝试过的代码,但是该值未出现在第二张纸上。 Does anybody know where the problem is in my attempt below? 有人知道我在下面的问题出在哪里吗?
Thx 谢谢
function onEdit() {
var a = [19,21,23]
var ss = SpreadsheetApp.getActive()
var s = ss.getActiveSheet();
if( s.getName() == "ALL" ) {
var valActive = s.getActiveCell();
var col = valActive.getColumn();
var row = valActive.getRow();
var range = s.getRange(row, 1);
var val0 = range.getValue();
if( a.indexOf(col) > -1 && valActive.getValue() != '') {
var nextCell = valActive.offset(0, 1);
var val1 = valActive.getValue();
var time = Utilities.formatDate(new Date, "GMT+1", "HHmm");
nextCell.setValue(val0 + '_' + val1 + '_' + time);
var rowNext = nextCell.getRow();
var colNext = nextCell.getColumn();
var target = SpreadsheetApp.getActive().getSheetByName("Samples");
var lastRow = target.getLastRow();
s.getRange(rowNext, colNext).copyTo(target.getRange(lastRow + 1, 1), {contentsOnly: true});
}
}
}
To get the second part to work you want to append a row to your other sheet. 要使第二部分工作,您需要在另一张图纸上追加一行。 Try something like this: 尝试这样的事情:
var sheet = SpreadsheetApp.getActive().getSheetByName("Name");
sheet.appendRow([newValue]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.