Computer >> Computer tutorials >  >> Software >> Office

Master Excel Advanced Filters: Two Proven Ways to Filter Data by Date Range

The dataset showcases the sales quantity of electronic products on different dates in January, February and March 2022.

Master Excel Advanced Filters: Two Proven Ways to Filter Data by Date Range

Method 1- Use the Sort & Filter Option to Apply the Advanced Filter to a Date Range

STEPS:

  • Create 3 column headers as shown below: Date, Products and Sales Qty.

Master Excel Advanced Filters: Two Proven Ways to Filter Data by Date Range

  • In the Date column, enter the criteria or range you want to apply. Here, extract sales after 31st January 2022.
  • In F6, enter >1/31/2022.
  • Click OK.

Master Excel Advanced Filters: Two Proven Ways to Filter Data by Date Range

>1/31/2022 indicates the date after 31st January 2022.

To filter the data based on the criteria:

  • Select the entire dataset B4:D14.
  • Go to the Data tab and select Advanced in Sort & Filter.

Master Excel Advanced Filters: Two Proven Ways to Filter Data by Date Range

  • In Advanced Filter, select Copy to another location.
  • List range is showing the selected range, as the whole dataset was selected.

Master Excel Advanced Filters: Two Proven Ways to Filter Data by Date Range

  • Enter $F$4:$H$5 in Criteria Range.
  • Enter $F$7 in Copy to.
  • Press Enter to see the output.

Master Excel Advanced Filters: Two Proven Ways to Filter Data by Date Range

  • You can change the criteria and apply advanced filtering based on the date range, Products or Sales Qty.

Master Excel Advanced Filters: Two Proven Ways to Filter Data by Date Range

Method 2 – Applying Excel VBA to Use the Advanced Filter for a Date Range

STEPS:

  • Create 2 column headers: Start and End Date.

Master Excel Advanced Filters: Two Proven Ways to Filter Data by Date Range

To extract information about the sales of January 2022, enter the Start date as 1st January and the End date as 31st January.

Master Excel Advanced Filters: Two Proven Ways to Filter Data by Date Range

  • To declare the criteria in the VBA code, the header must be the same.
  • In F8, enter the following formula:
  • Click OK.

Master Excel Advanced Filters: Two Proven Ways to Filter Data by Date Range

=”>=”&F5 copies the value from F5 and sets a criterion. The criterion indicates greater or equal to that value. The formula sets the criterion in F8 as greater or equal to 1st January 2022.

  • In G8, enter the following formula:
  • Click OK.

Master Excel Advanced Filters: Two Proven Ways to Filter Data by Date Range

=”<=”&G5 copies the value in G5 and sets a criterion. The criterion is less or equal to that value. The formula sets the criterion in G8 as less or equal to 31st January 2022.

  • Go to the Developer tab and click Visual Basic.

Master Excel Advanced Filters: Two Proven Ways to Filter Data by Date Range

  • In the Microsoft Visual Basic Application window, click Insert >> Module.

Master Excel Advanced Filters: Two Proven Ways to Filter Data by Date Range

  • Enter the following code in the module:
Sub myAdvancedFilterForDateRange()
Dim eb As Workbook
Dim es As Worksheet
Dim Rg As Range
Dim CRg As Range
Dim DRg As Range
Set eb = ThisWorkbook
Set es = eb.Worksheets("VBA Code")
Set Rg = es.Range("B4").CurrentRegion
Set CRg = es.Range("F7").CurrentRegion
Set DRg = es.Range("F10")
DRg.CurrentRegion.Clear
Rg.AdvancedFilter xlFilterCopy, CRg, DRg
End Sub

Master Excel Advanced Filters: Two Proven Ways to Filter Data by Date Range

  • Rg variable is the starting range of the dataset. CRg variable is the starting point of the criteria and DRg variable the starting place where the resultant dataset will be shown.
  • DRg.CurrentRegion.Clear clears the area.
  • Rg.AdvancedFilter xlFilterCopy, CRg, DRg  indicates the advanced filtering process.
  • Run the code by clicking the following icon:

Master Excel Advanced Filters: Two Proven Ways to Filter Data by Date Range

  • The sales information for January 2022 is displayed.

Master Excel Advanced Filters: Two Proven Ways to Filter Data by Date Range

Download Practice Workbook

Download the following workbook.

<< Go Back to Advanced Filter | Filter in Excel | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!