excel - copy rows from Sheet1 to Sheet2 automatically -
i want copy rows sheet1 sheet2 automatically whenever there new row added in sheet1.
well done more think since asked how vba here how vba.
'this goes in sheet1 code window private sub worksheet_change(byval target range) dim rws& rws = sheets("sheet1").range([a1], activesheet.usedrange).rows.count application.enableevents = false dim integer dim n integer = 1 rws n = 1 30 sheet2.cells(i, n).value = sheet1.cells(i, n).value next n next application.enableevents = true end sub
this replicate active rows , columns 1-30 sheet2 in excel file, make code replicate more columns edit value for n = 1 30.
edit: edited after jean-françois corbett kindly pointed out forgot mention included 30 columns.
edit2: code insert row instead of directly copying values - note code inserts row , copies data tested simple =sum , seems work well.
dim currow integer private sub worksheet_change(byval target range) dim rws& rws = sheets("sheet1").range([a1], activesheet.usedrange).rows.count application.enableevents = false dim integer dim n integer = 1 rws n = 1 30 if > currow sheet2.cells(i, n).insert shift:=xldown end if sheet2.cells(i, n).value = sheet1.cells(i, n).value next n next currow = rws application.enableevents = true end sub
Comments
Post a Comment