• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Advice on simple gap filling Macro?

Charter

New Member
Hi,
I'm pretty new to VBA and would like to write a simple Macro to hunt down rows until a gap is found and then fill this gap with data copied from the row above - the number of columns might vary but 'A' will always have a continuous list of timestamps. I've attached a sample file below.

Any advice on how I might best go about this would be great :)
 

Attachments

  • EG1.xlsx
    12.9 KB · Views: 5
Hi !

At beginner level using Excel basics :​
Code:
Sub Demo1()
          Dim Rg As Range
          Application.ScreenUpdating = False
With Sheet1.UsedRange.Offset(, 1).Rows
          Set Rg = .Columns(1).Find("", LookAt:=xlWhole)
    While Not Rg Is Nothing
        .Item(Rg.Row - 1).Copy Rg
          Set Rg = .Columns(1).FindNext(Rg)
    Wend
End With
          Application.ScreenUpdating = True
End Sub
Do you like it ? So thanks to click on bottom right Like !
 
Hi Marc,

Wow, that was quick and works very nicely - thank you.... now I just need to understand how it works :)

Cheers.
 
At medium level, instead of copying row by row this new
demonstration works with consecutive empty rows block :​
Code:
Sub Demo2()
         Dim Rg As Range
With Sheet1.UsedRange.Offset(, 1).Rows
         If Application.CountBlank(.Columns(1)) = 0 Then Exit Sub
         Application.ScreenUpdating = False
    For Each Rg In .Columns(1).SpecialCells(xlCellTypeBlanks).Areas
       .Item(Rg(0).Row).Copy Rg
    Next
End With
         Application.ScreenUpdating = True
End Sub
You may Like it !

 
Back
Top