How to filter all date cells before or after today in Excel?
In this article, I will talk about how to filter all date cells which before or after today in Excel worksheet.
Filter all date cells before or after today with Filter function
Filter all date cells before or after today with VBA code
Filter all date cells before or after today with Filter function
In fact, the Filter feature in Excel can help you to solve this task as quickly as you can, please do as this:
1. Select the date column that you want to filter, and then click Data > Filter, see screenshot:
2. Then click the drop down arrow, and then choose Date Filters > Before / After as you need, see screenshot:
3. In the Custom AutoFilter dialog box, click Date Picker button, and then click Today button in the date picker calendar, see screesnhot:
4. Then click OK to close the dialog, and all dates before or after today have been filtered out as following screenshot shown:
Filter all date cells before or after today with VBA code
The following VBA codes also can help you to filter all dates before or after current day in a worksheet. Please do with below steps:
1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste one of the following codes in the Module Window.
VBA code: Filter all date cells before today:
Sub FilterDateBeforeToday()
Dim xLastRow As Long
Dim xRg As Range
On Error Resume Next
Set xRg = Application.InputBox("Please select filtered column:", "KuTools for Excel", Selection.Address, , , , , 8)
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
ActiveSheet.AutoFilterMode = False
If xRg.Count = 1 Then Set xRg = xRg.CurrentRegion
xRg.AutoFilter 1, "<" & CDbl(Date)
Application.ScreenUpdating = True
End Sub
VBA code: Filter all date cells after today:
Sub FilterDateBeforeToday()
Dim xLastRow As Long
Dim xRg As Range
On Error Resume Next
Set xRg = Application.InputBox("Please select filtered column:", "KuTools for Excel", Selection.Address, , , , , 8)
If xRg Is Nothing Then Exit Sub
Application.ScreenUpdating = False
ActiveSheet.AutoFilterMode = False
If xRg.Count = 1 Then Set xRg = xRg.CurrentRegion
xRg.AutoFilter 1, ">" & CDbl(Date)
Application.ScreenUpdating = True
End Sub
3. After copying and pasting one of the above codes, then press F5 key to run this code, and a prompt box will pop out to remind you selected the date column that you want to filter, see screenshot:
4. And then click OK button, all date cells which before or after today will be filtered out immediately.
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!