I'm trying to filter dates in column A that are in the format 09-Jul-24.
The following code will not return any records for a single date (9th of July), but will correctly filter for the entire month of interest (including 12 records for the 9th of July).
What am I doing wrong?
The following code will not return any records for a single date (9th of July), but will correctly filter for the entire month of interest (including 12 records for the 9th of July).
What am I doing wrong?
VBA Code:
Sub TestDayFilter()
Dim EarningsDay As Long, StartDate As Long, EndDate As Long
EarningsDay = Sheets("Invoicing").Range("L1").Value
With Sheets("Invoicing").Range("L1")
StartDate = DateSerial(Year(.Value), Month(.Value), 1)
EndDate = DateSerial(Year(.Value), Month(.Value) + 1, 0)
End With
Sheets("Operations").Select
If ActiveSheet.FilterMode = True Then
ActiveSheet.ShowAllData
End If
Selection.AutoFilter Field:=1, Criteria1:=EarningsDay
Selection.AutoFilter Field:=1, Criteria1:=">=" & StartDate, Operator:=xlAnd, Criteria2:="<=" & EndDate
End Sub