Writing macros to add rows to a table

kec7

New Member
Joined
Feb 27, 2012
Messages
2
I want to write a macro that will allow me to add rows to a table in Excel. I would like to do this across several tabs. I would like the macro to find the last row in my table with data in it, and then add a row below the last row. After adding the row, I would like it to copy the formulas from the row above it into the new row. I’m not sure how to do this because the last row with data in it will not be on the same place on each sheet.

After I add the row, I would like to make the ranges in a summary formula I have written update to include the new rows that I added. I'm not sure if this is possible, but any help would be greatly appreciated!!
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
you need not ADD a row after the lasts row , it is already available

try this macro


Code:
Sub test()
Dim r As Range
Set r = Cells(Rows.Count, "A").End(xlUp)
r.EntireRow.Cut r.Offset(1, 0)
  ' should it be cut or copy. this row will be empty if cut is usesd
'for copying whole data to sumary
Range(Range("A1"), Cells(Rows.Count, "A").End(xlUp)).EntireRow.Copy
Worksheets("summary").Range("a1").PasteSpecial
Application.CutCopyMode = False
End Sub
 
Upvote 0
Thanks! I ended up using this, which seems to work. Thanks again for your reply.

Sub NewRowMacro()

Cells.Find(What:="Deliverable / Milestone", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate


ActiveCell.Offset(2, 0).Select
Do While Not IsEmpty(ActiveCell)
ActiveCell.Offset(1, 0).Select
Loop


ActiveCell.EntireRow.Insert Shift = xlDown 'create new row
ActiveCell.Offset(-1, 0).EntireRow.Copy Cells(ActiveCell.Row, 1) 'copy previous row
ActiveCell.EntireRow.SpecialCells(xlCellTypeConstants).ClearContents

End Sub
 
Upvote 0

Forum statistics

Threads
1,221,444
Messages
6,159,914
Members
451,603
Latest member
SWahl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top