View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default macro to insert row and copy previous row + excel

This doesn't work on columns A:AB. It works on the entire row.

When I do this, I usually don't have anything to the right of the table and I
want the entire row inserted and copied.

If that's not what you want, post back.

Option Explicit
Sub testme()

Dim wks As Worksheet
Dim FirstTableRng As Range
Dim LastCellInTableCol1 As Range

With Worksheets("Sheet1") 'change to what you need
Set FirstTableRng = .Range("First_Table")
End With

With FirstTableRng.Columns(1)
Set LastCellInTableCol1 = .Cells(.Cells.Count)
End With

With LastCellInTableCol1
.EntireRow.Insert
.Offset(-2, 0).Copy _
Destination:=.Offset(-1, 0)
End With

End Sub

Biffo wrote:

I have a named range First_Table (A5:AB30 ) and a named range End_Table (A30).
I would like to insert a row above the named range End_Table (A30).
Then copy the contents and formula from cells F29:AB29 into the new row.

However every time I run the macro it seems to insert the new row in a
different place which is messing up my data.

Can anyone help me please?
--
Laura


--

Dave Peterson