Hi,
I am trying to filter two columns, one an effective date, the second an expiry date, to filter permits that were valid for a particular year. As the year of interest changes I have set up a userform which I can enter the year of interest.
I am successfully able to get the first filter >= to work, however, the filter for the second columns does not work that contain <=.
I can get the second filter to work if I remove the < and just have equal t. But this is not ideal as I can not filter the less than dates.
I have also tried having two criteria for the same column, criteria1 equals to, and criteria less than, with the Operator:=xlfiltervalues, though this does not work either as.
When I say it does not work, the result of the filter is that no data selected/shown in the sheet, even though I can clearly see data that should be selected in the filter and shown.
Why does >= work correctly but <= does not?
The following is the line of code I refer to:
Really appreciate any help.
Cheers
I am trying to filter two columns, one an effective date, the second an expiry date, to filter permits that were valid for a particular year. As the year of interest changes I have set up a userform which I can enter the year of interest.
I am successfully able to get the first filter >= to work, however, the filter for the second columns does not work that contain <=.
I can get the second filter to work if I remove the < and just have equal t. But this is not ideal as I can not filter the less than dates.
I have also tried having two criteria for the same column, criteria1 equals to, and criteria less than, with the Operator:=xlfiltervalues, though this does not work either as.
When I say it does not work, the result of the filter is that no data selected/shown in the sheet, even though I can clearly see data that should be selected in the filter and shown.
Why does >= work correctly but <= does not?
The following is the line of code I refer to:
VBA Code:
Public HPyr As Long
Dim wsHPHarv As Worksheet
Dim lastrow, lcol As Long
Sub org_Harv_Permit_sht()
Set wsHPHarv = ThisWorkbook.Worksheets("HP harvester permits")
lastrow = wsHPHarv.Range("B" & Rows.Count).End(xlUp).Row
lcol = wsHPHarv.Cells(1, Columns.Count).End(xlToLeft).Column
wsHPHarv.Range(wsHPHarv.Cells(1, 1), wsHPHarv.Cells(lastrow, lcol)).AutoFilter field:=5, Criteria1:=">=1/01/" & HPyr
wsHPHarv.Range(wsHPHarv.Cells(1, 1), wsHPHarv.Cells(lastrow, lcol)).AutoFilter field:=6, Criteria1:="<=31/12/" & HPyr
End Sub
Really appreciate any help.
Cheers