In Excel, how to fill blank cells with the last preceding non-blank cell?

后端 未结 1 797
醉话见心
醉话见心 2021-01-14 06:12

How to fill blank cells with the last preceding non-blank cell ?

For example, I have this two-columns sheet:

A   
    abc
    dce
    fds
B   
    kj         


        
相关标签:
1条回答
  • 2021-01-14 06:35
    • 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!

    0 讨论(0)
提交回复
热议问题