[英]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.