Excel 在列中查找某个值的最后一次出现

Excel 在列中查找某个值的最后一次出现,excel,google-apps-script,spreadsheet,vba,Excel,Google Apps Script,Spreadsheet,Vba,我正在将vba脚本转换为google应用程序脚本,并且正在努力找到获取列中最后一个变量的最佳方法 在vba中,我可以执行以下操作: Worksheets("variants").Range("A:A").Find(what:=productid, after:=Range("A1"), searchdirection:=xlPrevious).row 然而,在谷歌应用程序脚本中,函数没有searchdirection参数。我可以通过使用自己的函数遍历列的值来解决这个问题,但是,这很慢。关于如何

我正在将vba脚本转换为google应用程序脚本,并且正在努力找到获取列中最后一个变量的最佳方法

在vba中,我可以执行以下操作:

Worksheets("variants").Range("A:A").Find(what:=productid, after:=Range("A1"), searchdirection:=xlPrevious).row

然而,在谷歌应用程序脚本中,函数没有searchdirection参数。我可以通过使用自己的函数遍历列的值来解决这个问题,但是,这很慢。关于如何使用google电子表格本机函数实现这一点,是否有其他方法?

您可以在类似
=ArrayFormula(max(row(a:a)*(a:a=B2))
的单元格中实现这一点。。。然而。。。我不认为这对你有帮助:/cool,好吧,我一直无法在应用程序脚本中使用本机函数,所以这正是我需要的。。。好 啊。。。很高兴我能帮忙:D
function getLastProductRow(ProductId){
  return runFunction('=ArrayFormula(max(row(A:A)*(A:A='+ProductId+')))')
}

//run spreadsheet function
function runFunction(formula){
  var cell = pvs.getRange("Z1");
  cell.setFormula(formula);
  return cell.getValue();
}