在第n行后向单元格插入公式,并在公式中将数字增加+1

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

我想在单元格A1,A5,A9等中使用公式=SUM(B2:B3),但想像这样=SUM(B5:B6)等来增加公式

google-sheets google-sheets-formula array-formulas google-sheets-query running-total
3个回答
0
投票

尝试:

=ARRAYFORMULA(IFERROR(IF(B1:B<>"",,QUERY(IF(B1:B="",,
 MMULT(N(TRANSPOSE(IF((TRANSPOSE(ROW(
 INDIRECT("B1:B"&MAX(IF(B1:B="",,ROW(B1:B))))))>=ROW(
 INDIRECT("B1:B"&MAX(IF(B1:B="",,ROW(B1:B))))))*(
 {""; TRANSPOSE(TRIM(SPLIT(QUERY(REPT("♦"&ROW(INDIRECT("B1:B"&COUNTBLANK(
 INDIRECT("B1:B"&MAX(IF(B1:B="",,ROW(B1:B))))))), 2)&"♦",,999^99), "♦")))}=TRANSPOSE(
 {""; TRANSPOSE(TRIM(SPLIT(QUERY(REPT("♦"&ROW(INDIRECT("B1:B"&COUNTBLANK(
 INDIRECT("B1:B"&MAX(IF(B1:B="",,ROW(B1:B))))))), 2)&"♦",,999^99), "♦")))})), 
 INDIRECT("B1:B"&MAX(IF(B1:B="",,ROW(B1:B)))), 0))), ROW(
 INDIRECT("B1:B"&MAX(IF(B1:B="",,ROW(B1:B)))))^0)), "offset 2", 0))))

0


0
投票

如果要拖动公式,请使用:

=IF(B1<>"",,SUM(INDIRECT("B"&ROW()+1&":B"&ROW()+2)))

0


0
投票

我发现这也有效:

=ARRAYFORMULA(IF((MOD(ROW(A:A),3)=1)*({B2:B;""}<>""),VLOOKUP(FLOOR(ROW(A:A)-1,3),QUERY({FLOOR(ROW(A:A)-1,3),N(B:B)*(MOD(ROW(B:B)-1,3)>0)},"select Col1,SUM(Col2) group by Col1"),2,0),))

Here is a sample sheet

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