Auto Populate cells from bottom to top vba

Closed
lin - Aug 19, 2010 at 05:38 AM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Aug 20, 2010 at 08:47 AM
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



Related:

1 response

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Aug 20, 2010 at 08:47 AM
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
0