Macros- Auto Copy paste row when cell value changes

Copper Contributor
I am not very experienced with excel so need help to do the following: I have column headers in columns A:G In the row below I have blank cells for data input. When column g has text input, I want a macro to automatically copy the row (sans data) and paste in the row below. For example if data is entered in G3, macro should copy row 3, insert and paste in row 4, delete contents of copied data in row 4. This sequence should repeat each time data is entered in any cell in column G. The very last row has formulas to calculate totals. I have the following macro to copy, insert row, and paste: Sub InsertRow() ' ' InsertRow Macro ' ' ActiveCell.EntireRow.Select Selection.Copy Selection.Insert Shift:=xlDown On Error Resume Next ActiveCell.Offset(1, 0).EntireRow.Cells.SpecialCells(xlCellTypeConstants).ClearContents On Error GoTo 0 ActiveCell.Offset(1, 0).Select Application.CutCopyMode = False End Sub I have the following macro to run the insert macro when the value in column G changes: Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$G$4" Then Application.EnableEvents = False InsertRow Application.EnableEvents = True End If End Sub Those work only when I change value in G4 however if I try to change the macro to apply to all of column G the macro goes crazy. I am unsure how to modify macro to run for the entire column G. Thank you in advance for any suggestions or assistance!
1 Reply

Hello @Hema12 ,

 

what is the big picture here? What are you trying to achieve with copy and pasting the rows? Do you need to duplicate formulas and formatting? If so, that can be done without VBA. Select the headers and the first row of data and use the command Insert > Table. With a table, ever row that is added below the last row will automatically have formulas and formatting applied.