How do I filter between two dates in YYYYMM format?

Knockoutpie

Board Regular
Joined
Sep 10, 2018
Messages
116
Office Version
  1. 365
Platform
  1. Windows
I'm really at a loss here as I cannot start my project without first completing this step..

In column 'A' I have dates in YYYYMM format and i'm trying to filter between ranges from YYYY-1/MM to YYYY/MM-1 (where YYYY/MM = current year/current month)

Between current year minus 1 year and then current year and month minus 1 month.

Any help would be greatly appreciated.

[TABLE="width: 61"]
<tbody>[TR]
[TD]YYYYMM[/TD]
[/TR]
[TR]
[TD]201805[/TD]
[/TR]
[TR]
[TD]201805[/TD]
[/TR]
[TR]
[TD]201706[/TD]
[/TR]
[TR]
[TD]201805[/TD]
[/TR]
[TR]
[TD]201902[/TD]
[/TR]
[TR]
[TD]201805[/TD]
[/TR]
[TR]
[TD]201805[/TD]
[/TR]
[TR]
[TD]201805[/TD]
[/TR]
[TR]
[TD]201805[/TD]
[/TR]
[TR]
[TD]201805[/TD]
[/TR]
[TR]
[TD]201805[/TD]
[/TR]
[TR]
[TD]201805[/TD]
[/TR]
[TR]
[TD]201805[/TD]
[/TR]
[TR]
[TD]201805[/TD]
[/TR]
[TR]
[TD]201805[/TD]
[/TR]
[TR]
[TD]201902[/TD]
[/TR]
[TR]
[TD]201805[/TD]
[/TR]
[TR]
[TD]201805[/TD]
[/TR]
[TR]
[TD]201805[/TD]
[/TR]
[TR]
[TD]201705[/TD]
[/TR]
[TR]
[TD]201805[/TD]
[/TR]
[TR]
[TD]201805[/TD]
[/TR]
[TR]
[TD]201804[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi,
if want VBA solution following untested but see if does what you want

Code:
Sub FilterDates()


        Dim StartDate As Long, EndDate As Long
    
        StartDate = DateSerial(Year(Date) - 1, 1, 1)
'0 - represents the last day of the previous month
        EndDate = DateSerial(Year(Date), Month(Date), 0)
        
'apply filter
        ThisWorkbook.Worksheets("Sheet1").UsedRange.AutoFilter Field:=1, _
                                                Criteria1:=">=" & StartDate, _
                                                Operator:=xlAnd, _
                                                Criteria2:="<=" & EndDate
End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,225,739
Messages
6,186,743
Members
453,370
Latest member
juliewar

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