简体   繁体   English

使用 AppScript 将行从一张表复制粘贴到另一张比较单元格值以避免重复

[英]Copy-Paste rows from one sheet to another comparing cell values to avoid duplicates using AppScript

 function copyRows() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var srcSheet = ss.getSheetByName("Form Responses 1"); var tarSheet = ss.getSheetByName("MasterDB"); var lastRow = srcSheet.getLastRow(); var Lr = tarSheet.getLastRow(); for (var i = 2; i <= lastRow; i++) { var cell = srcSheet.getRange("A" + i); var val = cell.getValue(); Logger.log(lastRow) for(var j=2; j<= Lr; j++) { var findstring = tarSheet.getRange("A" + j); var find =findstring.getValue(); // Logger.log(find) if (val == find) { continue; } var srcRange = srcSheet.getRange("A" + i + ":T" + i); var tarRow = tarSheet.getLastRow(); tarSheet.insertRowAfter(tarRow); var tarRange = tarSheet.getRange("A" + (tarRow+1) + ":T" + (tarRow+1)); srcRange.copyTo(tarRange); } } }

  • Hello,actually I'm trying copy & paste rows from one sheet to another within the spreadsheet,but to avoid duplicates,i'm comparing cell value from column A in both the sheets.您好,实际上我正在尝试在电子表格中将行从一张表复制并粘贴到另一张表中,但为了避免重复,我正在比较两张表中 A 列的单元格值。
    • column A is having Date & Time Stamp,which i'm comparing,if value matches,then don't copy &if not copy the particular range & paste on 'last row' of Master DB. A列有日期和时间戳,我正在比较,如果值匹配,那么不要复制&如果不复制特定范围并粘贴到主数据库的“最后一行”。
    • But with above code its just keep on copying rows multiple times,i'm not getting where exactly the error is.但是使用上面的代码,它只是继续多次复制行,我没有得到错误的确切位置。
    • Please help me with this,any help will be appreciated,Thanks in Advance.请帮助我,任何帮助将不胜感激,在此先感谢。
    • Sorry,if i have posted this in a wrong format,actually i'm new here.抱歉,如果我以错误的格式发布此内容,实际上我是新来的。
function copyRows() {
  var ss=SpreadsheetApp.getActive();
  var ssh=ss.getSheetByName("Form Responses 1");
  var tsh=ss.getSheetByName("MasterDB");
  var srg=ssh.getRange(2,1,ssh.getLastRow()-1,ssh.getLastColumn());//assume 1 header row
  var svs=srg.getValues();
  var trg=tsh.getRange(2,1,tsh.getLastRow()-1,1);//assume 1 header row
  var tvs=trg.getValues().map(function(r){return new Date(r[0]).valueOf();});
  svs.forEach(function(r,i){
    //if it is not in the target then append it to the target
    if(tvs.indexOf(new Date(r[0]).valueOf())==-1) {
      tsh.appendRow(r);
    }
  });
}

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

相关问题 将值从一张纸粘贴到另一张纸并删除重复的纸 - Paste values from one sheet to another and remove duplicates 从范围复制单元格值并将其粘贴到另一个工作表的单行中 - To copy Cell values from a range and paste it in a single row of another sheet 将单元格值从一张纸复制并粘贴到另一张onEdit - copy and paste cell value from one sheet to another onEdit 自动将值从一个谷歌工作表复制并粘贴到另一个 - Automatically copy and paste values from one google sheet to another 仅从一张纸复制值并粘贴到另一张纸上 - copy only values from one sheet and paste to another 如何在 Google 表格中复制粘贴带有超链接文本的单元格? - How to copy-paste a cell with hyperlinked text in Google Sheet? 如何使用 Google Sheets Macros 从一张工作表复制值并将它们粘贴到另一张工作表中? - How to copy values from one sheet and paste them into another using Google Sheets Macros? 复制单元格中的值并将值粘贴到同一工作表中的另一个单元格 - Copy values from cell and paste the values onto another cell in the same sheet 用于从一张纸复制并粘贴到另一张纸的数组 - An Array to copy and paste from one sheet to another 根据条件将单元格值从一个Google工作表复制到另一个 - Copy cell values from one google sheet to another based on condition
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM