简体   繁体   English

如何在当前单元格上方找到最近的非空白单元格?

[英]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):进一步说明我的需求的图像(并且可能会引出替代方法来做我想做的事):

SO32890557 Q 示例

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.

相关问题 用Google表格查询中最近的非空白单元格替换空白 - Replace blanks with nearest non-blank cell in Google Sheets query 如何在 Google Sheets 中找到一行中第一个非空白单元格的坐标? - How to find the coordinates of the first non-blank cell in a row in Google Sheets? 不可避免的合并单元格 - 用同一列中的先前非空白单元格填充空白单元格 - Unavoidable merged Cells - Fill blank cells with previous non-blank cell in same column 使用脚本选择最后一个非空白单元格在Google表格的下拉菜单中设置值 - Setting a value in a drop down with Google Sheets using a script to choose last non-blank cell 如何在当前单元格上方找到最接近的匹配值,并在同一行中返回不同的列? - How can I find the closest matching value ABOVE the current cell, and return a different column in that same row? 如何计算非空白单元格组和空白单元格组 - How to count groups of non-blank cells and blank cells 用 0 替换非空白单元格 - Replace non-blank cells with 0 如果单元格为空,如何将单元格留空? - How to leave cell blank if cell is blank? (谷歌表格或excel)如何在当前单元格上方找到最接近的匹配值,并在同一行中返回不同的列? - (google sheets or excel) How can I find the closest matching value above the current cell, and return a different column in that same row? 如何在Google脚本中获取非空白单元格的范围 - How to get the range of a non blank cell in google script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM