Share via

Inserting new row below active cell

Anonymous
2012-03-20T15:35:11+00:00

I would like to insert a new row below the current active cell and copy down the contents of column A of the row above the newly inserted. (I will be assigning this to a ribbon option)

Exp: If cell E7 is active. When the macro is run, it will insert a new row below that row and copy the contents of A7 to A8. These cell selections will be random. But the new row must always be below the active cell and only copy-down contents in column A.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-03-20T15:40:55+00:00

Hi,

try this..

(make a copy before..)

Sub InsertRow()

r = Selection.Row

Cells(r + 1, 1).EntireRow.Insert

Cells(r, 1).Copy Destination:=Cells(r + 1, 1)

End Sub

Was this answer helpful?

10+ people found this answer helpful.
0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2017-10-18T09:51:56+00:00

    Hi

    This was allready very helpful. Now I would like to insert data in this new row

    something like this (but this doesn't work):

    Dim newrow As ListRow

    r = Selection.Row

    Cells(r + 1, 1).EntireRow.Insert

    Set newrow = Cells(r + 1, 1)       <=This is where my problem is located!!

    With newrow

        .Range(2) = Me.tbBand

        .Range(3) = Me.tbTitle

        .Range(4) = Me.tbLabel

        .Range(5) = Me.tbReleaseDate

        .Range(6) = Me.tbCode

        .Range(7) = Me.tbDatePurchased

        .Range(8) = Me.tbGenre

        .Range(9) = Me.tbLand

        .Range(10) = Me.tbExtraInfo

    End With

    Would be very thankful if there is a simple solution for this matter.

    Greetz,

    Bart

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2017-08-14T20:19:30+00:00

    Using this method inserted cells accept formatting from row below (NOT above, despide setting CopyOrigin to xlFormatFromLeftOrAbove)

    ' I inserting new row at the end of the table before last line with sums etc.

    ' Inserted row is formatted exactly as whole table, not the last row.

    ' MovieNum - named range of first column (eg. A2:A43)

    Dim Rng as Range ' Needed to restore selection after Paste

    With Range("MovieNum")

      .Cells(.Count, 1).EntireRow.Insert Shift:=xlDown, _

        CopyOrigin:=xlFormatFromLeftOrAbove

      .Cells(.Count, 1).EntireRow.Copy

      Set Rng = Selection

    ' Never use Paste method if you have Conditional formatting, this will broke ranges

      .Cells(.Count - 1, 1).EntireRow.PasteSpecial _

        Paste:=xlPasteFormulasAndNumberFormats

      Rng.Select

      Application.CutCopyMode = False

      .Cells(.Count, 1).EntireRow.ClearContents

    End With

    Can anyone suggest an easier way?

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2012-03-20T16:50:27+00:00

    Simple & reliable, yet Powerful. This is perfect and works great... Thanks for the rapid response...

    Was this answer helpful?

    0 comments No comments