vba - Excel 2010: Need to copy certain cells to different worksheet based on cell value -
i have spreadsheet in excel 2010, wanting take cells in row , copy them worksheet when value entered specific cell in same row.
for example: in worksheet a, in cell a2, if "x" entered, want cell a5, a7 , a13-17 copied worksheet b. in worksheet b, should copied next available row, need them copied specific cells (not same in worksheet a- i.e: cell a5 need copy cell 2 in worksheet b; a7 cell 4 , a13-17 10-14). , cells copied in worksheet b need created in new row.
i have vba similar; however, copies entire row. above, need specific cells , won't match same cells in worksheet b.
here have been able work (to copy entire row):
sub testing_issue(byval target range) 'disable events code doesn't re-fire when row deleted application.enableevents = false 'was change made column t? if target.column = 20 'if yes, target read "y"? if target = "y" 'if y, determine next empty row in sheet "test" nxtrw = sheets("test").range("a" & rows.count).end(xlup).row + 1 'copy row open worksheet , move test worksheet target.entirerow.copy destination:=sheets("test").range("a" & nxtrw) else msgbox ("that not valid entry") end if end if 're-enable events application.enableevents = true end sub
i tried using following instead of entire row part, not work.
target.range("a13").copy destination:=sheets("test").range("a5 & nxtrw") target.range("b13").copy destination:=sheets("test").range("c5 & nxtrw") target.range("i13:j13").copy destination:=sheets("test").range("e5 & nxtrw")
i appreciate advice, need working right. please let me know if not clear.
i'm not sure want copied , want pasted to, started in right direction:
private sub worksheet_change(byval target range) dim rngcheck range dim checkcell range dim lrow long set rngcheck = intersect(me.columns("t"), target) if not rngcheck nothing each checkcell in rngcheck.cells if checkcell.value = "y" sheets("test") lrow = .cells(.rows.count, "a").end(xlup).row + 1 me.cells(checkcell.row, "a").copy destination:=.cells(lrow, "a") me.cells(checkcell.row, "c").copy destination:=.cells(lrow, "b") me.cells(checkcell.row, "i").copy destination:=.cells(lrow, "e") me.cells(checkcell.row, "j").copy destination:=.cells(lrow, "f") end end if next checkcell end if end sub
Comments
Post a Comment