How to copy a line in excel using a specific word and pasting to another excel sheet? -


i have checked bunch of different posts , can't seem find exact code looking for. have never used vba before i'm trying take codes other posts , input info work. no luck yet. @ work have payroll system in excel. trying search name "clarke, matthew" , copy row , paste workbook have saved on desktop "total hours".

tried , tested

sub sample()     dim wb1 workbook, wb2 workbook     dim ws1 worksheet, ws2 worksheet     dim copyfrom range     dim lrow long '<~~ not integer. might give error in higher versions of excel     dim strsearch string      set wb1 = thisworkbook     set ws1 = wb1.worksheets("yoursheetname")      strsearch = "clarke, matthew"      ws1          '~~> remove filters         .autofiltermode = false          '~~> assuming names in col         '~~> if not change below whatever column letter         lrow = .range("a" & .rows.count).end(xlup).row          .range("a1:a" & lrow)             .autofilter field:=1, criteria1:="=*" & strsearch & "*"             set copyfrom = .offset(1, 0).specialcells(xlcelltypevisible).entirerow         end          '~~> remove filters         .autofiltermode = false     end      '~~> destination file     set wb2 = application.workbooks.open("c:\sample.xlsx")     set ws2 = wb2.worksheets("sheet1")      ws2         if application.worksheetfunction.counta(.cells) <> 0             lrow = .cells.find(what:="*", _                           after:=.range("a1"), _                           lookat:=xlpart, _                           lookin:=xlformulas, _                           searchorder:=xlbyrows, _                           searchdirection:=xlprevious, _                           matchcase:=false).row         else             lrow = 1         end if          copyfrom.copy .rows(lrow)     end      wb2.save     wb2.close end sub 

snapshot

enter image description here


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -