Excel 2003 VBA code for filtering

March 24, 2009 at 23:32:26
Specs: Windows XP
Hello,

I need to perform an Autofilter function in Excel 2003 that allows me to filter a list using the contents of another cell as the criteria. For example, I need to filter the data in Column I against the value in cell E6. Now I know the basic code to filter against values equal to the contents of E6, which is:

Range("I11").Select
Selection.AutoFilter
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
Selection.AutoFilter Field:=9, Criteria1:=Range("E6"), Operator:=xlAnd

However, how do I filter against values less than or equal to E6? I've tried playing around with this code but it only lets me set the criteria as less than or equal to a numeric value, i.e.

Range("I11").Select
Selection.AutoFilter
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
Selection.AutoFilter Field:=9, Criteria1:="<=7", Operator:=xlAnd

How can I write a code so that the list in Column I is filtered against values that are less than or equal to the contents of cell E6?


See More: Excel 2003 VBA code for filtering

Report •


#1
March 25, 2009 at 20:30:04
Range("I11").AutoFilter Field:=1, Criteria1:="<=" & Range("E6")

Report •

#2
March 25, 2009 at 23:54:02
Thanks DerbyDad03, that was exactly what I needed. Cheers!

Report •

Related Solutions


Ask Question