filter vba

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Filter vba

Filter vba

resolvedResolved · High Priority · Version 2007

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

Tue 21 Dec 2010: Automatically marked as resolved.

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

The dual nature of toolbar buttons

Many toolbar buttons are dual purpose, though the two purposes are often linked in some way. For example, Align Left aligns a cell's contents to the left of the cell. However, hold down Shift and press the Align Left button: Excel aligns the cell contents to the right.
You may respond: So what? Well, you can reduce the number of buttons on your toolbar to make your screen less cluttered and allow more room for, perhaps, some of your own commands. After all, what's the point of an Align Right button when Shift+Align Left does the same thing?

View all Excel hints and tips


Server loaded in 0.09 secs.