ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   vba autofilter two columns (https://www.excelbanter.com/excel-programming/396406-vba-autofilter-two-columns.html)

[email protected]

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


Ron de Bruin

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


Jim Jackson

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



[email protected]

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





All times are GMT +1. The time now is 02:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com