excel - How to copy filtered cells to a new worksheet using VBA -
i have code automatically filters data need , exports new workbook. however, need exported new sheet in same workbook. there way go this? using code:
sub testfilter() range("d1").autofilter field:=4, criteria1:="in scope" range("m1").autofilter field:=13, criteria1:="not assigned" range("ag1").autofilter field:=33, criteria1:="opening" activesheet.autofilter.range.copy workbooks.add.worksheets(1).paste cells.autofilter end sub
thank you!
you can try (excel 2013):
sub macro1() ' set auto-filter testing selection.autofilter activesheet.range("$a$1:$ag$3000").autofilter field:=1, criteria1:="john" ' firstname activesheet.range("$a$1:$ag$3000").autofilter field:=2, criteria2:="smith" ' lastname ' copy filtered data doing ctrl + right-arrow , ctrl + down arrow range("a1").select range(selection, selection.end(xltoright)).select range(selection, selection.end(xldown)).select selection.copy ' add sheet after existing 1 , paste values sheets.add after:=activesheet selection.pastespecial paste:=xlpastevalues, operation:=xlnone, skipblanks _ :=false, transpose:=false end sub
Comments
Post a Comment