0

我需要更改我的 Matching 函数,它匹配不同工作表上的两列并将匹配项返回到第三张工作表,以便它返回匹配的行

我一直在尝试,我的头在旋转,没有成功

谢谢

function RunMatch() {

  // 0 is the LookIn sht column # to match on 
  // 1 is the LookWith sht column # to match on 
  MatchCols("LookInSheet","LookWithSheet","PostbackSheet",0,1)  

}

function MatchCols(sShtName,tShtName,pbShtName,matchIn, matchWith){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var LookInSht = ss.getSheetByName(sShtName);
  var LookWithSht = ss.getSheetByName(tShtName);
  var PBSheet = ss.getSheetByName(pbShtName);

  var LookIn = LookInSht.getDataRange().getValues();
  var LookWith = LookWithSht.getDataRange().getValues();

  var list = [];

  for (i in LookIn){
    var curName = LookIn[i][matchColIn];
    var exists = true;

    for (j in LookWith){
      var curCheck = LookWith[j][matchColWith];
      if (curCheck == curName){
        exists = false;
        break;
      };
    }; // end for j

    list.push([exists ? "" : curName]);

  } // end for i

  PBSheet.getRange(1, PBSheet.getLastColumn() +1, list.length, 1).setValues(list);

}
4

1 回答 1

0

如果我理解正确,您希望包含从在 的列中找到 的列中的值时开始PostbackSheet的整行。LookInmatchColInLookInmatchColWithLookWith

而不是使用,只需在找到匹配项时exists添加行:list

if (curCheck == curName){
  list.push(LookIn[i]);
  break;
}

然后,当您写入时PBSheet,使用 list 的大小来确保范围是正确的大小:

PBSheet.getRange(1, PBSheet.getLastColumn() +1, list.length, list[0].length).setValues(list);
于 2016-08-08T00:34:20.673 回答