Copy the contents of the previous row to the next row

Sometimes when the data increases, we need to copy the contents of the previous row into the next row. This code will help you do that easily.

Option Explicit

Sub fill()

Dim r As Long, c As Integer, Lastrow As Long

With ActiveSheet

Lastrow = .Cells(.Rows.Count, “E”).End(xlUp).Row

For c = 1 To 4

For r = 4 To Lastrow

If Cells(r, c) = “” Then

If Cells(r, 5) <> “” Then

Cells(r, c).Value = Cells(r – 1, c).Value

End If

End If

Next r

Next c

End With

End Sub

 

Copy the above code into a standard module.

Users are saying about us...

  1. Barry Fitzpatrick

    A quicker way would be to use the “Copy” method.

    E.g. to copy the previous rows into the currently selected row use:
    selection.offset(-1,0).entirerow.copy cells(selection.row,1)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Terms and Conditions of use

The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.

Visit Us On TwitterVisit Us On FacebookVisit Us On Google PlusVisit Us On Youtube