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

filter vba

ResolvedVersion 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:

Importing Numbers in Excel 2010

Occasionally, when importing data into Excel you find that the some of the imported values are treated as text.

To convert these numbers to actual values, click on an empty cell and press Ctrl+C.

Next, select the range that contains the values you need to change and in the Clipboard Group on the Home tab, click the Paste drop-down arrow and choose Paste Special. In the Paste Special dialog box, select Add and then click OK.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.