简体   繁体   English

根据单元格值将行从一张纸复制到另一张纸

[英]Copy row from one sheet to another base on cell value

My knowledge of java is very light. 我对Java的了解很浅。 I've created that code form consulting 5, 6 code in here and the developers google group but can figure out the conditional thing. 我已经在这里和开发人员google组中创建了咨询5、6代码的代码形式,但是可以找出条件代码。

Basically i want to copy a whole row that contain the word "AAF" or "SEQ" or "K7" in column H to another sheet at the last line. 基本上,我想将H列中包含单词“ AAF”,“ SEQ”或“ K7”的整行复制到最后一行的另一张纸上。 Eventually I will want to delete the copied row. 最终,我将要删除复制的行。 I have't tried to implement the lastrow nor the delete row wet but right now I'm stock just to get the copy to work with the filter condition. 我没有尝试实现lastrow,也没有尝试删除删除行,但是现在我只是想让副本在过滤条件下工作。 If i take out the "for" loop the copy work. 如果我拿出“为”循环复制工作。

function copyrange() {

var sheet = SpreadsheetApp.getActiveSheet();
var destsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Feuille2"); //destination sheet >where to copy the source
var rangeToCopy = sheet.getRange(1, 1, sheet.getMaxRows(), 11); //source to copy
var data = sheet.getDataRange().getValues(); //variable for the filter

for (n=0; n<data.length; ++n) {
    if (data[n] == "AAF" || "SEQ" || "K7")
      rangeToCopy.copyTo(destsheet.getRange(1, 1));
    }
}

Finally found a code that work for me. 终于找到了对我有用的代码。

function Validation() {
          var sheet1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Needed');
          var sheet2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Acquired');

          var data = sheet1.getRange(1,1, sheet1.getLastRow(), sheet1.getLastColumn()).getValues();

          var dest = [];
          for (var i = 0; i < data.length; i++ ) {
Logger.log(data[i][7]);// just to check if the condition is true sometimes ;-)
            if (data[i][7] == "AAF" || data[i][7] == "SEQ" || data[i][7] == "K7"){ 
              dest.push(data[i]); 
            }
          } // here is the end of the for loop
        Logger.log(dest) ; // log the dest array instead
            if (dest.length > 0 ) { // if something has been written in your array then batch write it to the dest. sheet
            sheet2.getRange(sheet2.getLastRow()+1,1,dest.length,dest[0].length).setValues(dest);
            }
        }

暂无
暂无

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

相关问题 Google Script:根据值将行从一张纸复制到另一张纸 - Google Script: Copy row from one sheet to another depending on value 根据条件将单元格值从一个Google工作表复制到另一个 - Copy cell values from one google sheet to another based on condition 将单元格值复制到另一个工作表以匹配值 - Copy cell value to another sheet for matching value Google电子表格将值从一行复制到另一张工作表 - Google spreadsheet copy values from one row to another sheet 将一行从一个Google表格电子表格复制到表单提交中的另一表格 - Copy a row from one Google Sheet Spreadsheet to Another on Form Submit jQuery,在表中单击超链接值时,将其从一个单元格复制到同一行中的另一个单元格 - jQuery, Copy hyper-link value when clicked on it in table from one cell to another in the same row 在编辑时将动态单元格的值复制到另一个工作表 - Copy value of a dynamic cell to another sheet on edit 根据特定的键值将数据从一张纸复制到另一张纸 - Copy data from one sheet to another based on a specific key value 如何将范围从一个工作表复制到另一工作表的范围,然后重复复制到下一行 - How to copy a range from one sheet to a range in another sheet, then repeat copying to the next row down 将特定范围复制到从一个工作表到另一个工作表中的第一个空行和特定列 - Copy a specific range to from one sheet to the first empty row and specific column in another sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM