My code does not filter why is this

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
Office Version
  1. 2019
Platform
  1. Windows
It`s filtering on Col 11 but it just hides all the data and does not filter???

VBA Code:
[CODE=vba]Private Sub Filter_Jobs_By_Months_Click()
Dim Database(1 To 100, 1 To 15)
Dim My_Range As Integer
Dim colum As Byte
Dim ws As Worksheet
Dim qt As QueryTable

Application.ScreenUpdating = False

Set ws = ThisWorkbook.Worksheets("TGS JOB RECORD")

For Each ws In ActiveWorkbook.Worksheets
For Each qt In ws.QueryTables
qt.Refresh
Next qt
Next ws

ws.Range("A2").AutoFilter Field:=11, Criteria2:=Me.Months.Value

Application.ScreenUpdating = True


End Sub
[/CODE]
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Why is the autofilter outside the ws loop?

If all the data is hidden, nothing matches the criterion. Why are you using criteria2 rather than Criteria1?
 
Upvote 0
Why is the autofilter outside the ws loop?

If all the data is hidden, nothing matches the criterion. Why are you using criteria2 rather than Criteria1? I Changed it to 1 then back to 2 but now have an issue see below
VBA Code:
ws.Range("A2").AutoFilter Field:=11, Criteria1:=Me.Months.Value
This was working now has stopped working says run time error 91
 
Upvote 0
Again, why is that line outside the loop?
 
Upvote 0
Move it above the Next ws line.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,914
Messages
6,122,211
Members
449,074
Latest member
cancansova

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