Make Google Spreadsheet Formula Repeat Infinitely

烈酒焚心 提交于 2019-11-28 18:39:10

Let's say the In Time cells are in Column A, and Out Time cells are in Column B, and you want Time Spent to be in Column C. Put this formula in cell C2 (assuming A1, B1, and C1 contain headers, not data):

=ARRAYFORMULA(B2:B - A2:A)

The ARRAYFORMULA function instructs the spreadsheet to iterate the contained formula over the ranges given, and a reference without a final number like B2:B refers to a range that contains all the remaining rows in the spreadsheet.

If for some reason you find arrayformula tricky to use in your situation, an alternative option is to create a mirror of the table on another sheet using a query that has the formulas written into it.

E.g. if you have numbers in columns A and B and a formula to add them together:

=query(Data!A:B, "select A, B, A + B")

The benefit to this approach is that you'll often want to do aggregation and summarization on your form data, and you can kill two birds with one stone by doing that in the same query that you use to apply the formulas.

I'll mention one other trick that has been useful in the past when Google's query syntax has a gap in functionality. You can actually apply an array formula to the data before passing it in to the query function, like this following example, which has output equivalent to the previous query.

=query({Data!A:B, arrayformula(Data!A:A+Data!B:B)},
  "select Col1, Col2, Col3")

Note how the columns are no longer referred to by letter, but by Col1, Col2, etc.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!