This is just part of a vba code I am writing and simple date comparison is not working. I have one sheet with tons of data and the vba code creates a pivot table. The code runs fine and does filter out all the past dates but it does not filter out (Feb 3 and Feb 4) for some reason (today is Feb 29). It filters out all the other Feb dates properly but its just those two dates. Anyone know what is wrong?
With ActiveSheet.PivotTables("pivottable1").PivotFields("issuedate")
For Each pi In .PivotItems
If pi < Date Then
pi.Visible = False
End If
Next pi
End With
Have you checked that the column type is a date and not a string? Maybe try CDate(pi)?
If that doesn't work please post the dates that aren't working - maybe by doing a Debug.print(pi).