[英]How to find nearest non-blank cell above the current cell?
I have a column of data, and I need to find the previous non-blank cell.我有一列数据,我需要找到之前的非空白单元格。 For example, if I have the following data:
例如,如果我有以下数据:
foo
-
-
-
-
(formula)
where -
denotes a blank cell, then I want the (formula)
cell to find a reference to the cell containing foo
no matter how many blank cells are inserted between them.其中
-
表示一个空白单元格,然后我希望(formula)
单元格找到对包含foo
的单元格的引用,无论它们之间插入了多少空白单元格。 It is possible that new rows with blank cells in the test column could be inserted between the formula row and the previous non-blank row at any time, and the formula should be able to handle that.测试列中带有空白单元格的新行可以随时插入到公式行和前一个非空白行之间,并且公式应该能够处理这种情况。
Ideally, I would like to be able to put the formula in any cell on a row to find the nearest non-blank cell above that row in, say, column A.理想情况下,我希望能够将公式放在一行的任何单元格中,以找到该行上方最近的非空白单元格,例如 A 列。
An image to further illustrate my needs (and maybe elicit alternative ways to do what I want):进一步说明我的需求的图像(并且可能会引出替代方法来做我想做的事):
Use FILTER, ROW, MAX + ISBLANK() formulas to get it,使用 FILTER, ROW, MAX + ISBLANK() 公式得到它,
=FILTER(B1:B9, ROW(B1:B9)=MAX(FILTER(ARRAYFORMULA(ROW(B1:B9)), NOT(ISBLANK(B1:B9)))))
That does basically what you need.这基本上可以满足您的需求。 More precisely the below formula is "paste it anywhere" type as you asked, just paste the below formula on any cell and it will give you the last nonblank cell value.
更准确地说,下面的公式是“将其粘贴到任何地方”类型,只需将下面的公式粘贴到任何单元格上,它就会为您提供最后一个非空白单元格值。
=FILTER( INDIRECT(CHAR(64+COLUMN())&"1:"&CHAR(64+COLUMN())&ROW()-1) , ROW(INDIRECT(CHAR(64+COLUMN())&"1:"&CHAR(64+COLUMN())&ROW()-1))=MAX( FILTER( ARRAYFORMULA(ROW(INDIRECT(CHAR(64+COLUMN())&"1:"&CHAR(64+COLUMN())&ROW()-1))) , NOT(ISBLANK(INDIRECT(CHAR(64+COLUMN())&"1:"&CHAR(64+COLUMN())&ROW()-1))))))
如果公式要进入A9,请尝试:
=index($A:$A,match("zzz",$A$1:$A9))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.