vba - How to filter 4 numbers in column -
i know how filter 2 numbers less 25 , greater 50 , on, i'm wondering how filter 4 numbers between 250 , 290 or if between 70 , 110.
the codes have tried far
activesheet.range("$f$4:$ak$18").autofilter field:=26, _ criteria1:=">=70", operator:=xland, criteria2:="<=110" activesheet.range("$f$4:$ak$18").autofilter field:=26, _ criteria1:=">=250", operator:=xland, criteria2:="<=290"
and
activesheet.range("$f$4:$ak$18").autofilter field:=26, _ criteria1:=array(">70", "<110", ">250", "<290"), operator:=xlfiltervalues
and
activesheet.range("$f$4:$ak$18").autofilter field:=25, _ criteria1:=">=70", operator:=xland, criteria2:="<=110", operator:=xland, _ criteria2:=">=250", operator:=xland, criteria2:="<=290"
none of these work can im wondering if im trying possible.
you need advanced filter trying achieve. here how apply:
range("a5:c10").advancedfilter action:=xlfilterinplace, criteriarange:=range _ ("a1:d2"), unique:=false
- make sure data has column headers.
- you need create criteria section above main data. this, insert @ least 3 blank rows above data. first 1 headers, second 1 criteria; third 1 required blank (to separate main data , criteria section. see image below.
- copy/paste column titles main data newly created first row (see image below).
- starting second row, provide criteria. each criterion row "or"ed other criteria rows. if need "and" them, use single row.
- if need "and" 2 or more conditions on single column, create new columns in criteria range same title. example, wanted add 2 conditions on sales column in image below, added 2 sales columns (c , d) in criteria range.
- provide conditions using standard operators.
- now choose advanced filter dialog data tab in main ribbon. select data range (a5:c10 in example), criteria range (a1:d2 in example) , click ok. make sure not include blank row when selecting criteria range.
see this article more examples.
Comments
Post a Comment