Google App脚本电子表格复制和粘贴行在粘贴时是重复行

时间:2022-09-17 11:38:05

Google Spreadsheet Code has been created to copy and paste a row of data into a target sheet in the same spreadsheet. However, when the row is being pasted into target sheet it is pasting it twice. I need to only have it pasted into the target location once... Not Twice.

已创建Google电子表格代码,用于将一行数据复制并粘贴到同一电子表格中的目标工作表中。但是,当行被粘贴到目标工作表时,它会粘贴两次。我只需要将它粘贴到目标位置一次......不是两次。

Please See Sheet: https://docs.google.com/spreadsheets/d/1dL9FkxPawP9kvqJ4SwfRLqcv9HAUjHhZCfG9wxOwlDY/edit?usp=sharing

请参阅表格:https://docs.google.com/spreadsheets/d/1dL9FkxPawP9kvqJ4SwfRLqcv9HAUjHhZCfG9wxOwlDY/edit?usp=sharing

Script:

function onEdit(event)
{ 
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = event.source.getActiveSheet();
  var r = event.source.getActiveRange();
  var curDat = new Date();
 
  var valSent = r.getValue().toString().toLowerCase();
  
  if(s.getName().toString() == "Referrals 2015" && r.getColumn() == 15 && valSent == "sent" && valSent!="")
  {
    var row = r.getRow();
    var numColumns = s.getLastColumn();
    var targetSheet = ss.getSheetByName("Auths and F&D");
    
    var target = targetSheet.getRange(targetSheet.getLastRow()+1, 1);
    var target1 = targetSheet.getRange(targetSheet.getLastRow()+1, 3);
    var target2 = targetSheet.getRange(targetSheet.getLastRow()+1, 4);
    var target3 = targetSheet.getRange(targetSheet.getLastRow()+1, 5);    
    var tRow =targetSheet.getLastRow();
    
    s.getRange(row,1,1,2).copyTo(target);
    s.getRange(row,5,1, 1).copyTo(target1);
    s.getRange(row,12,1, 1).copyTo(target2);
    s.getRange(row,13,1, 2).copyTo(target3);
    targetSheet.getRange(tRow+1, 7).setValue(curDat);
    targetSheet.getRange("B" +targetSheet.getLastRow()+3+":Z"+targetSheet.getLastRow()+3).copyTo(targetSheet.getRange("B" + targetSheet.getLastRow()), {formatOnly: true});  
    targetSheet.getRange(tRow+1,1,1,7).setBackgroundColor("#ffff00");
    
    r = null;
    s = null;
    valSent="1";
  }
}

1 个解决方案

#1


onEdit() runs automatically as a simple trigger. If you have it set up in the scripts triggers from Resources>This project triggers, you need to remove it as it will run once as a simple trigger and again as an installed trigger.

onEdit()作为简单触发器自动运行。如果您在资源>此项目触发器的脚本触发器中设置了它,则需要将其删除,因为它将作为简单触发器再次作为已安装的触发器运行一次。

#1


onEdit() runs automatically as a simple trigger. If you have it set up in the scripts triggers from Resources>This project triggers, you need to remove it as it will run once as a simple trigger and again as an installed trigger.

onEdit()作为简单触发器自动运行。如果您在资源>此项目触发器的脚本触发器中设置了它,则需要将其删除,因为它将作为简单触发器再次作为已安装的触发器运行一次。