excel - VBA: Filter table data based on drop down selection -
i filter table column c, based on drop down list selection. have more lines, can select country code form drop down list.
i filter table based on country code selection.
for example:
first line: "54" country code selected
second line "24" country code selected
and on....
the table on other tab filtered selected country code "54","24".
can please me how can manage it?
thank :)
sub filterrangecriteria() dim vcrit variant dim wsfiltered worksheet dim wsselection worksheet dim rngcrit range dim rngorders range dim lastrow integer 'you need more variables save range in array dim valarr variant dim cl range dim integer set wsfiltered = worksheets("s") ' want filter tab "centre information" selection set wsselection = worksheets("centre information") set rngorders = wsfiltered.range("b:b") 'i want filter column lastrow = worksheets("centre information").cells(rows.count, 2).end(xlup).row myrange = ("b3:b" & lastrow) ' value b3 until last row: filter data set rngcrit = wsselection.range(myrange) vcrit = rngcrit.value 'i error here: autofilter method of range class failed 'correction: fill array redim valarr(lastrow - 3) 'define array size (first 2 rows empty + considering first array position starts 0) = 0 each cl in rngcrit 'loop through range valarr(i) = "=" & cl 'filter each value + operator = + 1 next cl 'correction: use array als range of numbers shall matched rngorders.autofilter _ field:=1, _ criteria1:=valarr, _ operator:=xlfiltervalues end sub
comment: if want filter range, using autofilter have provide array contains values in string format. filtering numbers requires operator: e.g. "=", "<=", etc. best regards.
Comments
Post a Comment