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.

YYYYMM
201805
201805
201706
201805
201902
201805
201805
201805
201805
201805
201805
201805
201805
201805
201805
201902
201805
201805
201805
201705
201805
201805
201804

<tbody>
</tbody>
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
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,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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