excel - Advanced.Filter VBA -
i have code far, sheet 2, how can alter code include multiple sheets this? complete newb here. :
sub extractuniquevalues() sheet1.range("c:c").advancedfilter xlfiltercopy, , sheet4.range("c1"), true sheet2.range("c:c").advancedfilter xlfiltercopy, , sheet4.range("c1"), true end sub
you can that:
filter data in place:
sub extractuniquevalues() dim wks excel.worksheet each wks in excel.activeworkbook.worksheets call wks.range("c:c").advancedfilter(xlfilteraction.xlfilterinplace, , , true) next wks end sub
filter data , paste them new worksheet:
sub extractuniquevalues2() dim wks excel.worksheet dim wkssummary excel.worksheet '---------------------------------------------------------------------------------- on error resume next set wkssummary = excel.thisworkbook.worksheets("unique data") on error goto 0 if wkssummary nothing set wkssummary = excel.thisworkbook.worksheets.add wkssummary.name = "unique data" end if 'iterate through worksheets, skip [summary] worksheet. each wks in excel.activeworkbook.worksheets wkssummary if wks.name <> .name if application.worksheetfunction.counta(wks.range("c:c")) call wks.range("c:c").advancedfilter(xlfiltercopy, , .cells(.cells(.rows.count, 1).end(xlup).row + 1, 1), true) end if end if end next wks end sub
unique data each worksheet printed in first column of new worksheet called unique data.
this method filters data each worksheet separately, if there example value a
in sheet1 , value a
in sheet2, there 2 entries a
in result list.
note first value considered header , can duplicated in result list.
Comments
Post a Comment