我希望从1周开始在googleSheet中编写一个宏来比较不同电子表格中的两个不同列。我在GoogleScript编辑器中使用Javascript进行编码。
这两列填充了ID号,它们可以有不同的长度。在第一张纸上,该列为[A],在第二张纸上为[E] 如果列[E]中的某些ID不在列[A]中,我想在[A]的底部添加ID,其中包含相同ID行的一些信息。
这是我的代码,带有一些注释,因为它有点复杂。
我不明白为什么它不起作用。
任何帮助都感激不尽。
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
// move from sheet to sheet begining after the Sheet 2
for(var a = 2; ss.getSheets()[a];a++){
var lastRow = ss.getSheets()[a].getLastRow();
var lastCol = ss.getSheets()[a].getLastColumn();
//Move from row 1 to bottom in the other sheets
for (var j = 1; i <= lastRow; j++){
// Move from row 1 to bottom in the MASTER TABLE
for ( var i = 1; j <= ss.getSheets()[1].getLastRow() ; i++){
//Cell [E2], [E3] ... cell [A2], [A3] ...
if (ss.getActiveRange()[E,i].getValue() == ss.getSheets() [1].getActiveRange()[A,j].getValue() ){
break // If == then out of the loop and go to i=i+1
}else{
j = j + 1; // if != then stay with [E,i] but compare to [A,j+1]
}
// if this [E,i] isn't in the column [A] then it add a row and insert the following values to this new row
//this will add a new row and paste the values form sheet(a) in range [A] to [D]
ss.getSheets()[1].insertRowAfter(lastRow-1).appendRow(ss.getSheets() [a].getSheetValues(i, 5 ,1, 4));
// this will add an information form sheet(a).colomn 52 in the cell [F,lastRow-1]
// It will overwrite when passing to the next sheet but OK
ss.getSheets()[1].getRange(lastRow-1,5,1,1).appendRow(ss.getSheets()[a].getSheetValues(i, 52 ,1, 1));
// This will add an information form sheet(a).column 54 in the cell [a+4,lastRow-1]
// a is 2,3,4 ... And will paste in columns 6,7,8... ([F],[G],[H]) this is why [a+4]
ss.getSheets()[1].getRange(lastRow-1,a+4,1,1).appendRow(ss.getSheets()[a].getSheetValues(i, 54 ,1, 1));
}
}
}
}