Auto Populate cells from bottom to top vba

[Closed]
Report
-
Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
-
Hello,
i would like write a vba script to fills the blank cells with the value of the cell directly below it starting from top to bottom with a loop

e.g

blank cell 1
blank cell 2
blank cell 3
blank cell 4
12345
blank cell 5
blank cell 6
77777

blank cell 1 to 4 should be fill with 12345
while blank cell 5 to 6 should be fill with 77777



1 reply

Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
768
Try this

Sub FillUp()
Dim lRow As Long
Dim sLastValue As String
    
    lRow = Cells(Rows.Count, "A").End(xlUp).Row
    
    Do While True
        
        If (Cells(lRow, 1) <> "") Then
           sLastValue = Cells(lRow, 1)
        Else
            Cells(lRow, 1) = sLastValue
        End If
    
        lRow = lRow - 1
        If (lRow = 0) Then Exit Do
        
    Loop
    
End Sub

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!