AutoFilter Multi Columns with Date

airforceone

Board Regular
Joined
Feb 14, 2022
Messages
190
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
good day mate,

need some guidance again, my code do run when not filtering between dates! but when I include the Date Covered in the range it does not show/filter intended record(s).

VBA Code:
Sub AutoFilterDate()

    Dim sDate As Long
    Dim eDate As Long
   
    sDate = Range("H1").Value
    eDate = Range("I1").Value
       
    ActiveSheet.AutoFilterMode = False
           
    With Sheet10
        If Not .AutoFilterMode Then .Range("A1").AutoFilter
        .Range("A1").AutoFilter Field:=2, Criteria1:=">=" & sDate, Operator:=xlAnd, Criteria2:="<=" & eDate, Operator:=xlAnd ' This is where the issue is
        .Range("C1").AutoFilter Field:=3, Criteria1:="Bob", Operator:=xlAnd
        .Range("C1").AutoFilter Field:=4, Criteria1:="<50"
    End With
   
End Sub

2024.07 - XL2BB Record.xlsm
ABCDEFGHI
1DateItemSales RepQuantityPriceCommission2024.01.012024.03.01
22024.01.08ProjectorBob51,000.005%
32024.02.08PrinterMark3800.0010%
42024.03.08White BoardStacey10900.006%
52024.04.08PrinterMark15500.0010%
62024.05.08White BoardBob20600.0015%
72024.06.08ProjectorStacey25700.0010%
82024.07.08White BoardBob50400.003%
92024.01.01White BoardBob100200.005%
102024.06.01White BoardStacey2300.006%
112024.06.01PrinterStacey5200.0010%
122024.03.01PrinterStacey40100.005%
132024.03.01PrinterStacey50200.0010%
142024.05.01ProjectorBob50300.0020%
152024.04.01ProjectorMark30500.0015%
TestData
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
try

VBA Code:
Sub AutoFilterDate()

    Dim ws As Worksheet
    Dim sDate As Long
    Dim eDate As Long
 
    Set ws = ThisWorkbook.Sheets("Sheet10")
    sDate = ws.Range("H1").Value
    eDate = ws.Range("I1").Value
     
    If ws.FilterMode Then ws.ShowAllData
         
    With ws.Range("A1:F1")
        .AutoFilter Field:=1, Criteria1:=">=" & sDate, Operator:=xlAnd, Criteria2:="<=" & eDate, Operator:=xlAnd ' This is where the issue is
        .AutoFilter Field:=3, Criteria1:="Bob", Operator:=xlAnd
        .AutoFilter Field:=4, Criteria1:="<50"
    End With
  
    MsgBox "Done"
 
End Sub
 
Upvote 0
Solution
try

VBA Code:
Sub AutoFilterDate()

    Dim ws As Worksheet
    Dim sDate As Long
    Dim eDate As Long
 
    Set ws = ThisWorkbook.Sheets("Sheet10")
    sDate = ws.Range("H1").Value
    eDate = ws.Range("I1").Value
    
    If ws.FilterMode Then ws.ShowAllData
        
    With ws.Range("A1:F1")
        .AutoFilter Field:=1, Criteria1:=">=" & sDate, Operator:=xlAnd, Criteria2:="<=" & eDate, Operator:=xlAnd ' This is where the issue is
        .AutoFilter Field:=3, Criteria1:="Bob", Operator:=xlAnd
        .AutoFilter Field:=4, Criteria1:="<50"
    End With
 
    MsgBox "Done"
 
End Sub
seems to work fine mate, Big Thanks :)
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top