Filter for all dates except this month

Milos

Board Regular
Joined
Aug 28, 2016
Messages
121
Office Version
  1. 365
Platform
  1. Windows
Hi,

Can anybody please help me edit my clumsy coding please? I am trying to apply a filter that selects any date apart from dates within the last month. So if I use today for an example the filter will filter for all dates before and including 30/10/2018 because today's date is 30/11/2018. So far I have just been using 30 because that is the easiest option.

Code:
Sub Filter_Dates()
Dim date_all  As Long
Dim date_month As Long
date_all = DateSerial(Year(Date), Month(Date), Day(Date)) - 1000
date_month = DateSerial(Year(Date), Month(Date), Day(Date)) - 30
    
ActiveSheet.Rows(2).AutoFilter
ActiveSheet.Rows(2).AutoFilter Field:=3, Criteria1:=">=" & date_all, Operator:=xlAnd, Criteria2:="<=" & date_month
End Sub



End Sub

Thanks,
Milos
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
all dates before and including 30/10/2018 because today's date is 30/11/2018.
That's not the same thing as "this month" which is what's in your title. It's "date more than a month ago" which is what my explanation below will address.

any date apart from dates within the last month.
Can any of the dates be in the future? If so, then you need and "or" for

">" & Date

You don't need the first criterion. If you want all dates earlier than another date, then you don't need to specify an earliest date.

The quick fix you are looking for is

Code:
date_month = DateSerial(Year(Date), Month(Date) [COLOR=#ff0000]- 1[/COLOR], Day(Date))
 
Last edited:
Upvote 0
Whoops sometimes me and words have a few issues. Thanks 6StringJazzer. Really appreciate the help!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
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