3

如何用前面的最后一个非空白单元格填充空白单元格?

例如,我有这个两列的工作表:

A   
    abc
    dce
    fds
B   
    kjh
    abc

我想要的是:

A   
A   abc
A   dce
A   fds
B   
B   kjh
B   abc

我尝试了像“=IF(ISBLANK(A2), A1, A2)”这样的公式,但它警告我有关冗余并且不起作用。

4

1 回答 1

5
  • In a "manual" fashion, you could do the following:

Select the column, go to Edit > Go To > Special > Blanks, type = in the formula bars, hit the up arrow then Ctrl+Enter. you should now have the cells fill with the values above

  • In a more "automated" fashion using VBA, you could do the following:

Select the range where you want to fill the blank cells,

enter image description here

Then click on Developer Tab -> Visual Basic -> Insert -> Module

Then paste the code in the Module, and click on run:

enter image description here

Code:

 Sub Fill_Blank_Cells()
 Selection.SpecialCells(xlCellTypeBlanks).Select
 Selection.FormulaR1C1 = "=R[-1]C"
 End Sub

As @Jerry rightfully pointed out, make sure to copy-paste special the values in order to remove the formulas behind your filled column. This will prevent any undesirable results later!

于 2013-08-22T15:46:06.543 回答