Excel VBA - Auto FIlter and Advanced filter usage error -
i have requirement in, need use auto filter filter data first , using advanced filter unique values alone. advanced filter doesn't take auto filtered value alone. how use them together?
here goes code,
colmz = worksheetfunction.match("rsdate", sheets("rs_report").rows(1), 0) activesheet.listobjects("rs").range.autofilter field:=colmz, criteria1:="yes" activesheet.range("b1:b65536").advancedfilter action:=xlfiltercopy, copytorange:=sheets("csrs").range("b14"), unique:=true
kindly correct me , share suggestions.
i stick unique values in array - it's faster , less break -
sub uniquearray() colmz = worksheetfunction.match("rsdate", sheets("rs_report").rows(1), 0) activesheet.listobjects("rs").range.autofilter field:=colmz, criteria1:="yes" call creatary(curary, sheets("rs_report"), letter(sheets("rs_report"), "rsdate")): call eliminateduplicate(curary): call buildarraywithoutblankstwo(curary): call alphabetically_sortarray(curary) each cell in curary 'do need unique array list next cell end sub function creatary(ary variant, sh worksheet, ltr string) dim x, y, rng range redim ary(0) set rng = sh.range(ltr & "2:" & ltr & sh.range("a1000000").end(xlup).row).specialcells(xlcelltypevisible) x = 0 each y in rng if not application.iserror(y) if not isnumeric(y) ary(x) = y end if x = x + 1 redim preserve ary(x) end if next y end function function buildarraywithoutblankstwo(ary variant) dim aryfromrange() variant, arynoblanks() variant dim counter long, noblanksize long 'set references , initialize up-front redim arynoblanks(0 0) noblanksize = 0 'load range array aryfromrange = ary 'loop through array range, adding 'to no-blank array go counter = lbound(aryfromrange) ubound(aryfromrange) if ary(counter) <> 0 noblanksize = noblanksize + 1 arynoblanks(ubound(arynoblanks)) = ary(counter) redim preserve arynoblanks(0 ubound(arynoblanks) + 1) end if next counter 'remove pesky empty array field @ end if ubound(arynoblanks) > 0 redim preserve arynoblanks(0 ubound(arynoblanks) - 1) end if 'debug reference ary = arynoblanks end function function eliminateduplicate(ary variant) variant dim arynodup(), duparrindex, i, dupbool, j duparrindex = -1 = lbound(ary) ubound(ary) dupbool = false j = lbound(ary) if ary(i) = ary(j) , not = j dupbool = true end if next j if dupbool = false duparrindex = duparrindex + 1 redim preserve arynodup(duparrindex) arynodup(duparrindex) = ary(i) end if next ary = arynodup end function function alphabetically_sortarray(ary) dim myarray variant dim x long, y long dim temptxt1 string dim temptxt2 string myarray = ary 'alphabetize sheet names in array list x = lbound(myarray) ubound(myarray) y = x ubound(myarray) if ucase(myarray(y)) < ucase(myarray(x)) temptxt1 = myarray(x) temptxt2 = myarray(y) myarray(x) = temptxt2 myarray(y) = temptxt1 end if next y next x ary = myarray end function function letter(osheet worksheet, name string, optional num integer) if num = 0 num = 1 letter = application.match(name, osheet.rows(num), 0) letter = split(cells(, letter).address, "$")(1) end function
Comments
Post a Comment