excel - Apply macro filter across Multiple worksheet in a workbook and and save the filtered value as another workbook containing those multiple sheet -



excel - Apply macro filter across Multiple worksheet in a workbook and and save the filtered value as another workbook containing those multiple sheet -

i have workbook containing 23 work sheets. have apply macro auto-filter filter required info 23 work sheets , save info work book filtered info in 23 work sheets..

sub switch_filter() dim j integer, k integer, k1 integer dim lastrow integer, integer, erow integer dim s variant, s1 variant j = worksheets.count s = inputbox("enter switch id") s1 = s & "*" if s <> vbnullstring k = 1 20 if (k <> 1) , (k <> 4) , (k <> 7) worksheets(k) .usedrange.autofilter field:=3, criteria1:=s1 lastrow = .cells(.rows.count, "a").end(xlup).row = 3 lastrow range(cells(i, 1), cells(i, 36)).select selection.copy workbooks.open filename:="c:\users\takyar\documents\salesmaster-new.xlsx" worksheets(k).select erow = activesheet.cells(rows.count, 1).end(xlup).offset(1, 0).row activesheet.cells(erow, 1).select activesheet.paste activeworkbook.save activeworkbook.close application.cutcopymode = false next end end if next k end if end sub

almost completed, save's filtered info in same sheet of new workbook,here have attached code:-

sub switch_filter() dim j integer, k integer dim lastrow integer, integer dim s variant, s1 variant dim myworkbook workbook, newwork workbook set myworkbook = thisworkbook j = worksheets.count s = inputbox("enter switch id") s1 = s & "*" if s <> vbnullstring k = 1 20 worksheets(k) set myworkbook = thisworkbook if (k <> 1) , (k <> 4) , (k <> 7) .autofiltermode = false worksheets(k).usedrange .autofilter .autofilter field:=3, criteria1:=s1 end end if myworkbook.sheets(k).rows("1:65000").copy set newwork = workbooks.open("e:\spreed sheet\sample1.xlsx") newwork.worksheets(k) range("a2").pastespecial paste:=xlpasteall newwork.close end end next k end if end sub

pls suggest me solution.

thanks in advance....!!!

not sure if executing, didn't error occurring.

without information, think biggest problem copying 1 row @ time , opening , closing workbook every time want re-create row.

if want new workbook contain separate sheets filtered info might want consider creating new worksheet within old document filtered info , cutting/moving new document whole sheet @ time. - larn code recording macro , manually doing it.

otherwise, if can store info in 1 sheet/table i'd recommend loading each worksheet filtered info 1 single array , opening new workbook , writing of info array. alternative quickest.

excel vba excel-vba

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -