Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default vba autofilter two columns

I would like to be able to filter a sheet based off of two columns in
VBA. If I run the following one at a time I can filter based off the
one column, but if I run them both it will not work.

Worksheets("Master Index").Range(Cells(12, 42), Cells(65536,
42)).AutoFilter field:=1, Criteria1:="E", Operator:=2, Criteria2:="M/
E"

Worksheets("Master Index").Range(Cells(12, 163), Cells(65536,
163)).AutoFilter field:=1, Criteria1:="1", Operator:=2, Criteria2:="1"

Also, what is the field option used for?

Thank you for your help,
David

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default vba autofilter two columns

Normal your range is more then one column and you use the field to tell which column you want to filter.

See the example on this page and the tips below the macro
http://www.rondebruin.nl/copy5.htm#AutoFilter


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


wrote in message ups.com...
I would like to be able to filter a sheet based off of two columns in
VBA. If I run the following one at a time I can filter based off the
one column, but if I run them both it will not work.

Worksheets("Master Index").Range(Cells(12, 42), Cells(65536,
42)).AutoFilter field:=1, Criteria1:="E", Operator:=2, Criteria2:="M/
E"

Worksheets("Master Index").Range(Cells(12, 163), Cells(65536,
163)).AutoFilter field:=1, Criteria1:="1", Operator:=2, Criteria2:="1"

Also, what is the field option used for?

Thank you for your help,
David

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 324
Default vba autofilter two columns

Worksheets("Master Index").Range(Cells(12, 42), Cells(65536,
163)).AutoFilter field:=1, Criteria1:="E", Operator:=2, Criteria2:="M/
E"

Worksheets("Master Index").Range(Cells(12, 42), Cells(65536,
163)).AutoFilter field:=122, Criteria1:="1", Operator:=2, Criteria2:="1"

This should do it. The Field statement identifies the column number within
the range of columns you have selected for the autofilter. 1 is column 42,
122 is column 163 in your code.

--
Best wishes,

Jim


" wrote:

I would like to be able to filter a sheet based off of two columns in
VBA. If I run the following one at a time I can filter based off the
one column, but if I run them both it will not work.

Worksheets("Master Index").Range(Cells(12, 42), Cells(65536,
42)).AutoFilter field:=1, Criteria1:="E", Operator:=2, Criteria2:="M/
E"

Worksheets("Master Index").Range(Cells(12, 163), Cells(65536,
163)).AutoFilter field:=1, Criteria1:="1", Operator:=2, Criteria2:="1"

Also, what is the field option used for?

Thank you for your help,
David


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default vba autofilter two columns

Thank you for your help. Just before I saw you post, I found another
website that also explains auto filtering. Here is a link to this
source:
http://www.ozgrid.com/VBA/autofilter-vba-criteria.htm

Thanks,
David

On Aug 27, 4:00 pm, "Ron de Bruin" wrote:
Normal your range is more then one column and you use the field to tell which column you want to filter.

See the example on this page and the tips below the macrohttp://www.rondebruin.nl/copy5.htm#AutoFilter

--

Regards Ron de Bruinhttp://www.rondebruin.nl/tips.htm

wrote in oglegroups.com...
I would like to be able to filter a sheet based off of two columns in
VBA. If I run the following one at a time I can filter based off the
one column, but if I run them both it will not work.


Worksheets("Master Index").Range(Cells(12, 42), Cells(65536,
42)).AutoFilter field:=1, Criteria1:="E", Operator:=2, Criteria2:="M/
E"


Worksheets("Master Index").Range(Cells(12, 163), Cells(65536,
163)).AutoFilter field:=1, Criteria1:="1", Operator:=2, Criteria2:="1"


Also, what is the field option used for?


Thank you for your help,
David



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
autofilter on many columns inquirer Excel Discussion (Misc queries) 3 July 16th 06 04:32 AM
Which columns AutoFilter is on. [email protected] Excel Programming 1 June 21st 06 03:26 AM
Which columns AutoFilter is on. [email protected] Excel Programming 0 June 20th 06 11:50 PM
Which columns AutoFilter is on. [email protected] Excel Programming 0 June 20th 06 11:50 PM
VBA to set which columns in Autofilter miker1999[_10_] Excel Programming 2 February 15th 04 02:44 AM


All times are GMT +1. The time now is 05:43 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"