Aquila has attended:
Excel VBA Intro Intermediate course
Filter vba
Hi
I want to be able to auto filter using vba. I have used the current code, but it isn't working:
With ActiveSheet
.Range("$A$1:$T$1").AutoFilter Field:=19, Criteria1:=Array(FirstChosenWeek, SecondChosenWeek), Operator:=xlFilterValues
End With
Where FirstChosenWeek and SecondChosenWeek have been defined as intger.
A filter is put on, but is not pick anything up, and not sure why.
Thanks
Aquila
RE: filter vba
Hi Aquila, thanks for your query. I've tried out your code on data of my own by replacing the names of the Array elements and it works fine. I suspect your problem is to do with how the element name is being passed to the array. Double check how those FirstChosenWeek and SecondChosenWeek values are being arrived at because the rest of the logic is correct. Note that you might need to convert your integer to a string (there is a "String" function to do this) because using:
Array("1", "2")
...works fine for me on my data whereas:
Array(1, 2)
...switches on the Autofilter but returns no values. I think your problem lies here.
Hope this helps,
Anthony