FREE Excel STUFF
SearchSearch Excel Content
Excel Help. Popular
NEW! Multiple Excel Search & Links
Excel Formulas
Excel Macros
Excel Newsletter
PRODUCTS
Up to $139.00 FREE!
Categories & SearchSearch for software
Excel Templates
Excel Add-ins
Excel Training
More....
OTHER
Excel Development


Use AutoFilter in Excel VBA to Filter by Date & Time


NEW! More Books..
Add to Google advanced search! Free Help!

Add Excel Answers & Search To Your Google Toolbar Details

AutoFilter by Date and Time

Current Special! Complete Excel Excel Training Course for Excel 97 - Excel 2003, only $145.00. $59.95 Instant Buy/Download, 30 Day Money Back Guarantee & Free Excel Help for LIFE!

Got any Excel Questions? Free Excel Help .

See Also Links Below if Not Familiar With AutoFilter in VBA

  1. Excel VBA & AutoFilter AutoFilter provides us with a MUCH faster alternative to loops of all kinds
  2. Excel VBA AutoFilter Criteria How to add the criteria for AutoFilter in VBA.
  3. Excel VBA AutoFilter Dates Using dates in AutoFilter can be tricky if not using the US date format.

AutoFilter by Date & Time With VBA

The 3 example codes below show how we can AutoFilter by date and time with VBA code .

Sub ByDateTimeGreater()
Dim dDate As Date, dTime As Date
Dim strDate As String
Dim lDate As Long, dblTime As Double
Dim dDateTime As Double

    dDate = DateSerial(2006, 9, 12)
    lDate = dDate
    
    dTime = TimeSerial(12, 8, 0)
    dblTime = dTime
    
    dDateTime = lDate + dblTime
    Range("A1").AutoFilter
    Range("A1").AutoFilter Field:=1, Criteria1:=">" & dDateTime
End Sub


Sub ByCellDateTimeGreater()
Dim dDate As Date, dTime As Date
Dim strDate As String
Dim lDate As Long, dblTime As Double
Dim dDateTime As Double
Dim rDate As Range, rTime As Range

Set rDate = Sheet1.Range("G1") 'Cell housing date & time

    If Not IsDate(rDate) Then 'Check if valid
      MsgBox "Non valid date and time in Sheet1 G1)"
      Exit Sub
    End If
    
    dDate = DateSerial(Year(rDate), Month(rDate), Day(rDate))
    lDate = dDate
    
    Set rTime = rDate
    dTime = TimeSerial(Hour(rTime), Minute(rTime), Second(rTime))
    dblTime = dTime
    
    dDateTime = lDate + dblTime
    Range("A1").AutoFilter
    Range("A1").AutoFilter Field:=1, Criteria1:=">" & dDateTime
End Sub


Sub ByDateTimeEqual()
Dim dDate As Date, dTime As Date
Dim strDate As String
Dim lDate As Long, dblTime As Double
Dim dDateTime As Double

    dDate = DateSerial(2006, 9, 12)
    lDate = dDate
    
    dTime = TimeSerial(12, 8, 0)
    dblTime = dTime
    
    dDateTime = lDate + dblTime
    
    '= to does not work for non US date systems. So as with dates, we use
    'Greater than or Equal to and Less than or Equal to the SAME date & time.
	Range("A1").AutoFilter
    Range("A1").AutoFilter Field:=1, Criteria1:=">=" & dDateTime, Operator:= _
        xlAnd, Criteria2:="<=" & dDateTime
End Sub

Excel Dashboard Reports & Excel Dashboard Charts 50% Off

Special! Free Choice of Complete Excel Training Course OR Excel Add-ins Collection on all purchases totaling over $64.00. ALL purchases totaling over $150.00 gets you BOTH! Purchases MUST be made via this site. Send payment proof to special@ozgrid.com 31 days after purchase date.


Instant Download and Money Back Guarantee on Most Software

Excel Trader Package Technical Analysis in Excel With $139.00 of FREE software!

Add to Google Search Tips FREE Excel Help

Microsoft ® and Microsoft Excel ® are registered trademarks of Microsoft Corporation. OzGrid is in no way associated with Microsoft