Note: The other languages of the website are Google-translated. Back to English

如何在Excel中今天之前或之後過濾所有日期單元格?

在本文中,我將討論如何過濾Excel工作表中今天之前或之後的所有日期單元格。

使用過濾功能過濾今天之前或之後的所有日期單元格

使用VBA代碼過濾今天之前或之後的所有日期單元格


使用過濾功能過濾今天之前或之後的所有日期單元格

實際上,Excel中的篩選器功能可以幫助您盡快解決此任務,請執行以下操作:

1。 選擇要篩選的日期列,然後單擊 數據 > 篩選,請參見屏幕截圖:

今天的文檔過濾器1

2。 然後單擊下拉箭頭,然後選擇 日期過濾器 > 之前 / 根據需要,請參見屏幕截圖:

今天的文檔過濾器2

3。 在 自定義自動篩選 對話框,單擊 日期選擇器今天的文檔過濾器3 按鈕,然後單擊 今天 日期選擇器日曆中的按鈕,請參見screesnhot:

今天的文檔過濾器4

4。 然後點擊 OK 關閉對話框,並過濾掉今天之前或之後的所有日期,如以下屏幕截圖所示:

今天的文檔過濾器5


使用VBA代碼過濾今天之前或之後的所有日期單元格

以下VBA代碼也可以幫助您過濾工作表中當天之前或之後的所有日期。 請執行以下步驟:

1。 按住 ALT + F11 鍵打開 Microsoft Visual Basic for Applications 窗口。

2。 點擊 插入 > 模塊,然後將以下代碼之一粘貼到 模塊 窗口。

VBA代碼:過濾今天之前的所有日期單元:

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.


The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office / Excel 2007-2021 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

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!
officetab bottom
Comments (1)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
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
There are no comments posted here yet
Leave your comments
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations

Follow Us

Copyright © 2009 - www.extendoffice.com. | All rights reserved. Powered by ExtendOffice. | Sitemap
Microsoft and the Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.
Protected by Sectigo SSL