locked
Macro to auto fill contents on one row into another RRS feed

  • Question

  • Hello Guys,

    So i am looking for some input on how to make a macro on click button, which copies data from the previous row and copies the same value in next row.

    So Suppose in excel a row has : 12 13 14 15 in differenct cells in row 1. I want to copy 12 13 14 15 on row 2 when user clicks on a macro button. Im new to vba. Any tips on accomplishing this would be helpful

    Thanks a lot.

    Tuesday, September 17, 2013 4:53 PM

All replies

  • To always copy all of row 1 to all of row 2:

    Sub Copy1to2()
    Rows("1:1").Copy Rows("2:2")
    End Sub

    or if you need to push the old row 2 down:

    Sub Copy1ToNew2()
    Rows("1:1").Copy
    Rows("2:2").Insert xlDown
    End Sub

    To copy specific cells of row 1 to row 2

    Sub CopySomeCells()
    Dim myC As Range
    For Each myC In Range("A1,C1,E1,M1")
        myC.Copy myC.Offset(1, 0)
    Next myC
    End Sub

    If you need to insert a new row 2 before doing the copying

    Sub CopySomeInsertNew()
    Dim myC As Range
    Rows("2:2").Insert xlDown
    For Each myC In Range("A1,C1,E1,M1")
        myC.Copy myC.Offset(1, 0)
    Next myC
    End Sub
    Tuesday, September 17, 2013 6:44 PM