简体   繁体   English

是否有一个数组公式可以用上面单元格的内容填充列中的所有空白单元格?

[英]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.

相关问题 填写 ={ARRAYFORMULA()} 中的空白单元格 - Fill in blank cells in ={ARRAYFORMULA()} 不可避免的合并单元格 - 用同一列中的先前非空白单元格填充空白单元格 - Unavoidable merged Cells - Fill blank cells with previous non-blank cell in same column &#39;Arrayformula&#39; 引用上面单元格中的值,在数组列中? - 'Arrayformula' which references values in cells above, within array column? Google Spreadsheet,在具有arrayformula的同一列中对上面的行单元格进行操作 - Google Spreadsheet, operations with above row cell in same column with arrayformula 使用 ARRAYFORMULA 连接列中的单元格 - CONCATENATE cells in the column with ARRAYFORMULA 如何检查一个单元格是否大于谷歌表格中的所有单元格,并对一整列单元格执行此操作(动态范围) - How to check if a cell is greater than all cells above in google sheets, and do this for a whole column of cells (dynamic range) 具有数组公式的列中的可编辑单元格 - Editable Cells in a Column with an arrayformula 如何自动填充列中的空白单元格 - How to auto fill blank cells in column Arrayformula 将非空白单元格之间的空白单元格编号为 0 到 n - Arrayformula to number blank cells between non-blank ones from 0 to n 动态sumif单元格范围包括活动单元上方的所有单元格 - Dynamic sumif cell range to include all cells above active cell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM