简体   繁体   English

将单元格值从一张纸复制并粘贴到另一张onEdit

[英]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: 该代码包括以下两个步骤:

  1. (works): If a cell of specific columns of one sheet are edited, then the next adjacent cell gets a value based on the edit. (有效):如果编辑了一张纸中特定列的单元格,则下一个相邻的单元格将基于该编辑获得一个值。

  2. (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.

相关问题 onEdit 特定单元格将数据从一个谷歌表格复制到另一个 - onEdit specific cell copy data from one google sheets to another 用于从一张纸复制并粘贴到另一张纸的数组 - An Array to copy and paste from one sheet to another 如果单元格值 = x,则有效地将行复制并粘贴到另一个工作表 - Efficiently Copy and Paste Row to Another Sheet if Cell Value = x onEdit:如何从另一个工作表中引用单元格并从该单元格写入一个单元格值偏移量? - onEdit: How to reference cell from another sheet and write a cell value offset from that cell? 使用 AppScript 将行从一张表复制粘贴到另一张比较单元格值以避免重复 - Copy-Paste rows from one sheet to another comparing cell values to avoid duplicates using AppScript 从范围复制单元格值并将其粘贴到另一个工作表的单行中 - To copy Cell values from a range and paste it in a single row of another sheet 根据列中单元格的值,将范围从一张纸复制/粘贴到其他几张 - Copy/paste a range from one sheet to several others depending on the value of a cell in a column Google Sheets + Apps Scripts,从一个工作表复制/粘贴到另一个工作表,但粘贴到特定列 (B) 中的第一个空单元格 - Google Sheets + Apps Scripts, Copy/Paste from one sheet to another, but Paste into first empty cell in specific column (B) 将每行中的值从一个单元格复制到另一个单元格,作为 Google 工作表中的“值” - copy a value from one cell to another cell per row as “value” in Google sheet 根据单元格值将最后一行从一个工作表复制到另一个工作表,并在主工作表中不断更新 - Copy last row from one sheet to another depending on cell value with constant updates in master sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM