google-apps-script - 谷歌表格=间接()在单元格范围上

标签 google-apps-script google-sheets google-sheets-formula

我想知道是否有一个标准函数可以循环一系列单元格并对其应用间接函数。 我正在尝试构建一个工作表来按商店、月份和类别来支付我的费用,但到目前为止它还很难扩展,因为我有一个看起来像这样的函数

=INDIRECT(""&$B$3&"!"&concat(A12,$C$1))+INDIRECT(""&$B$4&"!"&concat(A12,$C$1))+INDIRECT(""&$B$5&"!"&concat(A12,$C$1))+INDIRECT(""&$B$6&"!"&concat(A12,$C$1))

其中 B3:B7 是我的商店,这样读起来会容易得多:

=forEach(B3:B7, INDIRECT(""& B3:B7 &"!"&concat(A12,$C$1)))

或者类似的东西。

我尝试过使用 arrayFormula,但在这种情况下不起作用,因为我不是尝试在 2 个相同大小的范围上应用函数,而是在要查找的单个值范围上应用函数

简明问题: 是否有现有的函数,或者我必须尝试编写自己的函数?

最佳答案

我为我的具体问题找到了一个非常针对具体用例的解决方案。 发布是为了完整性,但仍然想知道其他人是否有更好的东西。

function indirectLoop(range, cellReference) {
  var currentCell = SpreadsheetApp.getActiveSheet().getActiveCell();
  var numberOfStores = range.length;

  var total = 0;

  var debugString = "";
  var currentStore;
  var storeSheet;
  var storeCell;
  for (var i = 0; i < numberOfStores; i++) {
    currentStore = range[i];
    storeSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(currentStore);
    storeCell = storeSheet.getRange(cellReference);

    total = total + storeCell.getValue();
    //debugString += currentStore + ":" + storeCell.getValue() + "- ";

  }
  return(total);
}

关于google-apps-script - 谷歌表格=间接()在单元格范围上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48924554/

相关文章:

javascript - 使用辅助帐户在 Gmail 中合并邮件

google-sheets - 无需身份验证 token 即可访问 Google 电子表格 API

arrays - Google Sheets QUERY 从选项卡名称列表中提取,这将在添加新选项卡时提取新选项卡数据

javascript - 将公式从 JavaScript 添加到 CSV 以导入到 Google 表格会导致多列

google-sheets - 过滤不在谷歌表格列表中的数据的功能是什么?

regex - 如何计算单元格是否在 Google 表格中的单词末尾包含 *

javascript - 如何返回 false 而不是 "TypeError: Cannot read property"?

javascript - 谷歌脚本错误: "Incorrect range width" when using setValues

javascript - 如何判断用户是否空闲并切换标签页?通过脚本(Google 电子表格 - GAS)

google-sheets - IMPORTHTML 使用 Google Sheets 抓取 Wiki 表特定列