Filter records between two dates
Question: How to filter rows using dates?
Answer:
In this post I will describe how to:
- Filter rows using array formulas (dynamic)
- Filter rows using excel table
- Filter rows using excel table and vba (dynamic)
Filter rows using array formulas
Array formula in cell D2:
=INDEX($A$2:$B$38, SMALL(IF(($A$2:$A$38=$H$1), MATCH(ROW($A$2:$A$38), ROW($A$2:$A$38)), ""), ROW(A1)), COLUMN(A1))
How to create an array formula
- Select cell D2
- Type the array formula
- Press and hold Ctrl + Shift
- Press Enter once
- Release all keys
How to copy array formula
- Select cell D2
- Copy cell D2 (Ctrl + c)
- Select cell D2:E9
- Paste (Ctrl + v)
How to remove #num errors
=IFERROR(INDEX($A$2:$B$38, SMALL(IF((A2:$A$38<$H$2)*(A2:$A$38>$H$1), MATCH(ROW(A2:$A$38), ROW(A2:$A$38)), ""), ROW(A1)), COLUMN(A1)),"")
Download excel sample file for this tutorial.
filter-records-between-two-dates.xls
(Excel 97-2003 Workbook *.xls)
Filter rows using an excel table
Convert range to a table
- Select range A2:B38
- Go to tab "Insert"
- Click "Table"
- Click OK!
Filter dates
- Click Black arrow near Date header
- Hover over "Date filters"
- Click "Between..."

- Select dates

- Click OK!
Filter rows using excel table and vba
In this example, you can type a date in cell B1 and B2. Press the button and the table is instantly filtered. Copy the vba code below into a standard module. Create a button and assign the macro.
VBA code
Sub TblFilterDates()
Worksheets("Sheet3").ListObjects("Table13").Range.AutoFilter _
Field:=1, Criteria1:=">=" & Worksheets("Sheet3").Range("B1") _
, Operator:=xlAnd, Criteria2:="<=" & Worksheets("Sheet3").Range("B2")
End SubWhere to copy vba code?
- Press Alt+F11
- Insert a new module
- Copy paste code into code window
How to create a button
- Click "Developer" tab
- Click "Insert" button
- Create a button (form control)
- Right click on the button
- Assign your macro
Download excel sample file for this tutorial.
filter-records-between-two-dates.xlsm
(Excel 2007 MacroEnabled Workbook *.xlsm)









September 15th, 2011 at 8:33 am
This is a great piece of programming, but I cannot for the life of me get it to work in my spread sheet. I have tried naming the ranges, adding dollar signs to keep the references constant, etc., but no matter what I do, it will not filter the date range correctly.
This is the perfect solution to my need, so if there is anything you can do to help me, I would appreciate it. I could send you the spreadsheet if that would help.
Thanks
Tom
September 16th, 2011 at 10:06 am
Tom,
I have updated the article. Let me know if you got it to work?
October 12th, 2011 at 5:15 am
Sir
What is table 13 here?
October 12th, 2011 at 12:03 pm
AVIUSHEK,
Table 13 is the table name.
How to find the table name
1.Select your table
2.Click "Design" tab on the ribbon
3.Read table name in properties window on the ribbon