aaronprudence
New Member
- Joined
- Apr 9, 2021
- Messages
- 4
- Office Version
- 365
- Platform
- Windows
Hi,
Very new to VBA and struggling. Any help would be very much appreciated. Thank you.
I have a workbook with several worksheets that I want to filter all at once to exclude the current month.
Data is in tables with date in Column Q.
Date is in dd/mm/yyyy format
I am getting a "AutoFilter method of Range Class failed" error
Very new to VBA and struggling. Any help would be very much appreciated. Thank you.
I have a workbook with several worksheets that I want to filter all at once to exclude the current month.
Data is in tables with date in Column Q.
Date is in dd/mm/yyyy format
I am getting a "AutoFilter method of Range Class failed" error
VBA Code:
Sub Exclude_Current_Month_Filter()
Dim ws As Worksheet, d1 As Long, d2 As Long
d1 = Date - Day(Date) 'End of last month
d2 = DateSerial(Year(Date), Month(Date) + 1, 1) 'Begining of next month
For Each ws In Worksheets
If ws.ListObjects.Count > 0 Then
ws.ListObjects(1).Range.AutoFilter 'clear previous filer if any
ws.ListObjects(1).Range.AutoFilter 17, "<=" & d1, xlOr, ">=" & d2 'Filter exclude current month column Q
End If
Next
End Sub