搜索所有 sheet 列 A 并找到符合特定条件的最后一个单元格的行

Search all sheet column A and find row of last cell matching specific criteria

This sheet is called 'Replenishment'

我想找到 ASIN 最后一次出现在名为 'Historic Sheet'

的 sheet 中的那一行

Here is the sheet called 'Historic Sheet'

我的当前代码找到了所有匹配项,而不是匹配条件 (ASIN) 的最终记录

  for (var i = 0; i < all.length; i++) {

  let tf = historicSheet.createTextFinder(asin);
  let all = tf.findAll();
  let unbookedStock = historicSheet.getRange(all[i].getRowIndex(), 18).getValue();
  historicSheet.getRange(all[i].getRowIndex(), 18).setValue(newValue);

}

我想可能是这样的:

function myFunction() {
  var asin = 'D0752NTHJz';
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Historic Sheet');
  var col_a = sheet.getRange('a:a').getValues().flat(); // get values from column A
  var row = col_a.lastIndexOf(asin) + 1; // this is the last row that contains the 'asin'

  console.log(row); 
}

这样试试:

function myFunction(asin = 'D0752NTHJz') {
  const ss = SpreadsheetApp.getActive();
  const sheet = ss.getSheetByName("Historic Sheet");
  const idx = sheet.getRange('A1:A' + sheet.getLastRow()).getValues().flat().lastIndexOf(asin);
  console.log('Row: %s',idx + 1); 
}