excel - Loop through filter criteria -
i've been trying figure out no progress...
i have filter (column d) , i'm trying create loop each criteria (i got @ least 1000 criterias) on filter. ex: each criteria on filter (column d), i'll run range copy...
that code isnt working @ all:
sub whatfilters() dim ifilt integer ifilt = 4 dim ifiltcrit integer dim numfilters integer dim crit1 variant activesheet.range("$a$1:$aa$4635").autofilter field:=16, criteria1:= _ "waiting" numfilters = activesheet.autofilter.filters.count debug.print "sheet(" & activesheet.name & ") has " & numfilters & " filters." if activesheet.autofilter.filters.item(ifilt).on crit1 = activesheet.autofilter.filters.item(ifilt).criteria1 ifiltcrit = 1 ubound(crit1) debug.print "crit1(" & ifiltcrit & ") '" & crit1(ifiltcrit) 'copy next ifiltcrit end if end sub
my mistake seems identifying filter column...
i realize asked while ago havent seen consider copy-paste ready. here came with. should work unlimited criteria. create single new sheet called "temp" can deleted once finished.
dim currentcell long dim numofvalues long sub filternextresult() ' copy , move data data sheet, column (can changed if needed) new sheet called "temp" ' check make sure there @ least 1 data point in column on temp sheet if currentcell = 0 application.screenupdating = false call createnewtemp application.screenupdating = true end if ' find total number of unique data points filtering in column of temp sheet if numofaccounts = 0 application.screenupdating = false call findnumofvalues application.screenupdating = true end if sheet1.usedrange .autofilter 1, worksheets("temp").range("a" & currentcell).value currentcell = currentcell + 1 ' check make sure havent reached end of clumn a. if exit sub if numofvalues + 1 = currentcell msgbox ("this last value filter by") exit sub end if end end sub 'sub number of values on temp sheet column private sub findnumofvalues() ' count number of non empty cells , assign value (less 1 title in our case) numofvalues numofvalues = worksheets("temp").range("a:a").cells.specialcells(xlcelltypeconstants).count end sub private sub createnewtemp() sheet1.range("a:a").copy activeworkbook.sheets.add.name = "temp" ' remove duplicates worksheets("temp").range("a1").select activeworkbook.activesheet .paste .range("a:a").removeduplicates columns:=array(1), header:=xlyes end ' check make sure there vlaues in temp sheet if worksheets("temp").range("a2").value = "" msgbox "there no filter values" end else currentcell = 2 end if sheet1.activate sheet1.range("a1").select selection.autofilter end sub
Comments
Post a Comment