Copy excel cell data till the nearest filled cell in column

前端 未结 1 1413
日久生厌
日久生厌 2021-01-26 22:15

I am a total newbie to Excel, and there\'s a bit of problem I am facing.

I have an Excel sheet that I have to import into another program of mine. Please consider this f

1条回答
  •  清酒与你
    2021-01-26 23:08

    This can be done very quick either manually (no code) or programmatically (simple code) using SpecialCells which has a xlBlanks collection

    1. Manually

    • Select the cells in your first two columns
    • Press F5 ... Special ...Blanks
    • In the formula bar type =A1 where A1 is the first cell above your new selection of blanks
    • Hold the Ctrl key and press Enter to enter this formula in all the blank cells at once

    This is written up well here including instructions as to how to convert these formulae to values

    2. VBA

    Three samples are provided here

    This modified version of the second code would work on columns A:B (which appears to be your data layout)

    Sub FillColBlanks_Offset()
    'by Rick Rothstein  2009-10-24
    'fill blank cells in column with value above
    'http://www.contextures.com/xlDataEntry02.html
    'modified by brettdj
    Dim Area As Range, LastRow As Long
    On Error Resume Next
    With Columns("A:B")
        LastRow = .Find(What:="*", SearchOrder:=xlRows, _
                        SearchDirection:=xlPrevious, _
                        LookIn:=xlFormulas).Row
        For Each Area In .Resize(LastRow). _
            SpecialCells(xlCellTypeBlanks).Areas
            Area.Value = Area(1).Offset(-1).Value
        Next
    End With
    End Sub
    

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