Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

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:

doc filter defore today 1

2. Then click the drop down arrow, and then choose Date Filters > Before / After as you need, see screenshot:

doc filter defore today 2

3. In the Custom AutoFilter dialog box, click Date Pickerdoc filter defore today 3 button, and then click Today button in the date picker calendar, see screesnhot:

doc filter defore today 4

4. Then click OK to close the dialog, and all dates before or after today have been filtered out as following screenshot shown:

doc filter defore today 5


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:

doc filter defore today 6

4. And then click OK button, all date cells which before or after today will be filtered out immediately.


Recommended Productivity Tools for Excel

kte tab 201905

Kutools for Excel Helps You Always Finish Work Ahead of Time, and Stand Out From Crowd

  • More than 300 powerful advanced features, designed for 1500 work scenarios, increasing productivity by 70%, give you more time to take care of family and enjoy life.
  • No longer need memorizing formulas and VBA codes, give your brain a rest from now on.
  • Become an Excel expert in 3 minutes, Complicated and repeated operations can be done in seconds, 
  • Reduce thousands of keyboard & mouse operations every day, say goodbye to occupational diseases now.
  • 110,000 highly effective people and 300+ world-renowned companies' choice.
  • 60-day full features free trial. 60-day money back guarantees. 2 years of free upgrade and support.

Brings Tabbed Browsing and Editing to Microsoft Office, Far More Powerful Than The Browser's Tabs

  • Office Tab is designed for Word, Excel, PowerPoint and Other Office Applications: 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!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Abhinav Kumar · 6 months ago
    I HAVE DATA in a following format
    12/11/2018 16:10
    12/11/2018 16:10
    12/11/2018 16:10
    12/11/2018 16:10
    12/11/2018 16:10
    12/11/2018 16:10
    12/11/2018 16:10
    12/11/2018 16:10
    12/11/2018 16:10
    12/11/2018 16:10



    and I want to filter it for TODAY - LAST 7 Days Excluding Today , That is if today is 12 Dec I want filter for 12 Dec and December[ 11,10,9,8,7,6,5] .
    How to create custom filter for this in MS Excel