vba - Visual Basic-Excel copy only some column to other sheet -
is there way click , copy value of column other sheet.
this picture explain more:
here code have errors dont know why:
private sub worksheet_selectionchange(byval target range) sheets("sheetb").select ' find last row of data finalrow = cells(rows.count, 1).end(xlup).row ' loop through each row x = 1 finalrow ' decide if copy based on column in sheetb thisvalue = cells(x, 1).value if thisvalue = target.value cells(x, 1).resize(1, 33).copy sheets("sheetc").select nextrow = cells(rows.count, 1).end(xlup).row + 1 cells(nextrow, 1).select activesheet.paste sheets("sheetb").select end if next x end sub
try below code :
kindly add header columns on sheet b before running code. suggest using procedure worksheet_selectionchange event.
private sub worksheet_selectionchange(byval target range) application.enableevents = false on error resume next dim rngfind range dim firstcell string dim integer if target.column = 1 & target.value <> "" set rngfind = sheets("sheetb").columns(1).find(what:=target.value, lookin:=xlvalues, lookat:=xlwhole, searchorder:=xlbyrows) if not rngfind nothing firstcell = rngfind.address = 1 while not rngfind nothing sheets("sheetc").cells(i, 1).value = rngfind sheets("sheetc").cells(i, 2).value = rngfind.offset(0, 1) sheets("sheetc").cells(i, 3).value = target.offset(0, 1) = + 1 set rngfind = sheets("sheetb").columns(1).findnext(rngfind) if rngfind.address = firstcell exit loop end if application.enableevents = true end sub
Comments
Post a Comment