[英]Is there an arrayformula to fill all blank cells in a column with the content from the cell above?
In the following Google sheet:在下面的谷歌表中:
A B
------------------------
1| Tom | something |
2| | something |
3| John | something |
4| Lana | something |
5| | something |
6| | something |
7| Jason | something |
------------------------
I want an array formula applied to column A which will automatically fill any blanks with the last data in the cell above (or above that, if there are multiple blanks).我想要一个应用于列 A 的数组公式,它将自动用上方单元格中的最后一个数据填充任何空白(如果有多个空白,则在其上方)。
The result should look like this:结果应如下所示:
A B
------------------------
1| Tom | something |
2| Tom | something |
3| John | something |
4| Lana | something |
5| Lana | something |
6| Lana | something |
7| Jason | something |
------------------------
As the sheet can be massive, applying the formula to each cell is not practical.由于工作表可能很大,将公式应用于每个单元格是不切实际的。
If I paste the formula =if(ISBLANK(A2), A1)
into the blanks manually it will fill them, but dragging said formula over a whole column will not work.如果我手动将公式
=if(ISBLANK(A2), A1)
粘贴到空白处,它将填充它们,但是将所述公式拖动到整列上将不起作用。
Yes you can do it with vlookup, by creating an array that includes a row number and using the inexact lookup form of vlookup so that it finds the previous row that contains text:是的,您可以使用 vlookup 来做到这一点,方法是创建一个包含行号的数组并使用 vlookup 的不精确查找形式,以便它找到包含文本的前一行:
=ArrayFormula(query({vlookup(row(A:A),{if(A:A<>"",row(A:A)),A:A},2),B:B},"select Col1,Col2 where Col2 is not null"))
The simplest way to achieve this goal would be to create a new column, and use the formula =IF(ISBLANK($A2), $B1, $A2)
from B2 down.实现此目标的最简单方法是创建一个新列,并使用公式
=IF(ISBLANK($A2), $B1, $A2)
从 B2 向下。 I think that what you meant was that you can't simply replace the column in place, correct?我认为您的意思是您不能简单地替换原位的列,对吗? This would solve it in that case, but it is not a single arrayformula.
在那种情况下这会解决它,但它不是一个单一的数组公式。 If you are worried about inserting the formula into all rows, try selecting the first cell, CTRL+SHIFT+Down arrow key to select the full range, and CTRL+ENTER to paste the formula.
如果您担心将公式插入所有行,请尝试选择第一个单元格,按 CTRL+SHIFT+向下箭头键选择整个范围,然后按 CTRL+ENTER 粘贴公式。
If you truly need an arrayformula, one would hope that =ArrayFormula(IF(ISBLANK(A2:A), B1:B, A2:A))
or the like would work, but unfortunately Sheets does not iterate over the results of this formula so that it does.如果你真的需要一个数组公式,人们会希望
=ArrayFormula(IF(ISBLANK(A2:A), B1:B, A2:A))
或类似的东西会起作用,但不幸的是 Sheets 不会迭代这个公式的结果所以它确实如此。 Other functions (such as vlookup) do work properly, but I'm not sure how to compose a formula to achieve what you're looking to do here using those.其他功能(例如 vlookup)确实可以正常工作,但我不确定如何使用这些功能编写公式来实现您在这里要执行的操作。
To answer your Q in one word "NO" (though slightly simplistic).用一个词“NO”来回答你的问题(虽然有点简单)。
An approach that might suit is to filter ColumnA to select (Blanks)
only and in the first blank cell (in your case A2) enter:一种可能适合的方法是过滤 ColumnA 以仅选择
(Blanks)
并在第一个空白单元格(在您的情况下为 A2)中输入:
=A1
where the 1
is the number of the row immediately above the formula cell.其中
1
是公式单元格正上方的行号。
Copy down to suit and Edit > Copy > Edit > Paste special > Paste values only, then take off the filter.向下复制并编辑 > 复制 > 编辑 > 选择性粘贴 > 仅粘贴值,然后取消过滤器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.