Google Sheets ArrayFormula 创建支票寄存器

问题描述 投票:0回答:1

Google 表格 - 我正在尝试使用数组公式将前一行的 D 单元格添加到当前行的 C 单元格中,并将结果放入当前行的 D 单元格中。基本上它是一个检查注册表,所以如果我在第 2 行,D2 的公式将是 D3+C2。 我无法获得在 D2 中不给我 #REF 的公式。 有什么想法吗?电子表格图片

我想使用 ArrayFormula,这样如果我在某处插入一行,它会自动将公式复制到其中。

谢谢

我尝试使用 ChatGPT,它给了我一些使用行偏移的想法,但我仍然收到 REF 错误。

google-sheets array-formulas
1个回答
0
投票

建议:使用自定义功能

由于使用 Google 表格公式时这有点复杂,您可能需要使用 Google Apps 脚本来创建自定义函数。

脚本

function balance(amountList, currentBalance) {
  amountList.reverse().shift(); //reverses data arrangement and removes unwanted data
  var out = [];
  amountList.map(w=>w.map(x=>{
    currentBalance += x; //cummulative balance
    out.push([Number(currentBalance).toFixed(2)]);
  }))
  return out.reverse(); //returns the output
}

用法/函数语法

对于这个自定义函数,我决定将

amount column
current balance
作为输入。自定义函数语法应如下所示:

=余额(金额列表,当前余额)

在您的示例中,我假设

972.89
是当前余额。因此,我对 D2 使用以下公式:

=余额(C2:C10,D10)

应该是这样的:

output

参考资料:

© www.soinside.com 2019 - 2024. All rights reserved.