Trying to Filter for more the one it

itsgrady

Board Regular
Joined
Sep 11, 2022
Messages
132
Office Version
  1. 2021
Platform
  1. Windows
  2. MacOS
See bold italics part of the code. I am trying to filter the table for more than item. Seems like it would be easy but I am not having any luck. There is one column that I am trying to do the filter for more than one item.


Sub DMwill()

Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("VPI-All-WhsRpt")

Application.ScreenUpdating = False
If ws.AutoFilterMode Then
ws.AutoFilterMode = False
End If

Sheets("VPI-All-WhsRpt").Activate

ws.ListObjects("VPI_All_WhsRpt").AutoFilter.ShowAllData

ws.ListObjects("VPI_All_WhsRpt").Range.Select

ws.ListObjects("VPI_All_WhsRpt").Range.AutoFilter Field:=11, Criteria1:=("204", "201", "105”)

Set rng = ws.Range("A10")
rng.Select
rng.Application.Goto rng, True
Set rng = Nothing
Set ws = Nothing

Application.ScreenUpdating = True

End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Should probably looks something more like this
VBA Code:
ws.ListObjects("VPI_All_WhsRpt").Range.AutoFilter Field:=11, Criteria1:=("204"), Operator:=xlOr, Criteria2:= ("201"), Operator:=xlOr, Criteria3:=("105”)
 
Upvote 0
See bold italics part of the code. I am trying to filter the table for more than item. Seems like it would be easy but I am not having any luck. There is one column that I am trying to do the filter for more than one item.


Sub DMwill()

Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("VPI-All-WhsRpt")

Application.ScreenUpdating = False
If ws.AutoFilterMode Then
ws.AutoFilterMode = False
End If

Sheets("VPI-All-WhsRpt").Activate

ws.ListObjects("VPI_All_WhsRpt").AutoFilter.ShowAllData

ws.ListObjects("VPI_All_WhsRpt").Range.Select

ws.ListObjects("VPI_All_WhsRpt").Range.AutoFilter Field:=11, Criteria1:=("204", "201", "105”)

Set rng = ws.Range("A10")
rng.Select
rng.Application.Goto rng, True
Set rng = Nothing
Set ws = Nothing

Application.ScreenUpdating = True

End Sub

Thanks for the reply.
I got a compile error - name argument not found. This was highlighted for the compile error: Criteria3:=

Can you help? I will have some that I will set up later with 5 or more filters.
 
Upvote 0
Try it like
VBA Code:
ws.ListObjects("VPI_All_WhsRpt").Range.AutoFilter Field:=11, Criteria1:=Array("204", "201", "105"), xlfiltervalues
 
Upvote 0
Try it like
VBA Code:
ws.ListObjects("VPI_All_WhsRpt").Range.AutoFilter Field:=11, Criteria1:=Array("204", "201", "105"), xlfiltervalues

Hello again.
It gave a compile error: Syntax Error
 
Upvote 0
Ok, try
VBA Code:
ws.ListObjects("VPI_All_WhsRpt").Range.AutoFilter 11, Array("204", "201", "105"), xlFilterValues
 
Upvote 1
Solution
Ok, try
VBA Code:
ws.ListObjects("VPI_All_WhsRpt").Range.AutoFilter 11, Array("204", "201", "105"),xlFilterValues

Thank you so much. I added Operator:= in front of xlFilterValues and it worked. You always provide great help. Thanks.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top