sorting - Filter by array of values on Excel -


i have question filtering rows in excel.

i have large table, on 10 000 rows. each row has unique id. duplicated table , made modifications on rows , highlighted them.

the thing need select rows based on array of values of unique id. (the id field this: 1, 2, 3, 4, 5,.., 10500) form unmodified copy of first excel table.

i demonstrating following sample data.

    sample tables filtering

the predominantly blue table in a1:d16 listobject named mytable. predominantly green table in f3:i13 listobject named mytable_copy.

to filter mytable listobject based on id's found in id column of mytable_copy, need construct array of id numbers strings. function can used that. remember filter expecting array of strings integers, not true integers. if have special number formatting leading zeroes, function have changed accommodate that.

tap alt+f11 , when vbe opens, use pull-down menus insert ► module (alt+i,m). paste following new module code sheet named book1 - module1 (code).

function gather_ids(stbl string, scol string)     dim aids() string, long, id range     each id in range(stbl & "[" & scol & "]")         redim preserve aids(0 i)         aids(i) = cstr(id.value2)         = + 1     next id     gather_ids = aids end function 

now need sub call function , filter mytable based on returned array. in same module sheet, paste following.

sub main()     dim vids variant      vids = gather_ids("mytable_copy", "id")      activesheet         .listobjects("mytable").range.autofilter field:=1, criteria1:=(vids), _             operator:=xlfiltervalues     end  end sub 

note variant array passed criteria1 parameter wrapped in brackets. the brackets important. without them, .autofilter command not recognize variant array array , use first value in array filter criteria.

tap alt+q return worksheet alt+f8 open macros dialog , run main macro. should receive results similar following.

      tables filtered array


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -