filter vba
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

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

Filter vba

resolvedResolved · High Priority · Version 2007

replyReply Wed 15 Dec 2010, 14:57Delegate Aquila said...

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

For upcoming training course dates see: Pricing & availability

replyReply Wed 15 Dec 2010, 15:39Trainer Anthony said...

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.

 

Please browse our web site to find out more about
excel classes and other Microsoft training courses.

Excel tip:

Bracketed negative numbers

Often Excel users wish to display negative numbers in colour red and bracketed

Intstructions
Step1. Select Format > Cells menu options. Within Numbers tabsheet, select Category = Custom.
Step 2. Select a type such as #,##0;[Red]-#,##0;; that specifies a colour in square brackets.
Step 3. Amend as follows; #,##0;[Red](#,##0;;

Notes: Excel formatting featues are of the form
"Positive; Negative;Zero;Text" separated by semicolon.

View all Excel hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard