I have a Pivot table and a button to filter between 2 dates. When I click the button I get an error 1004 Application Defined or Object Defined error
I found the error was due to some non date values in the source cells on some rows.. when I change them to date values the code works correctly.
What I would like to know is there I way I can ignore these values, ie so non date values are ignored and not used in the filter? Currently the error stops the macro from continuing.
here's the code I have
Dim Invoice_Start_Date As Date
Dim Invoice_End_Date As Date
Invoice_Start_Date = CDate(Worksheets("Despatch Template").Cells(17, "F").Value)
Invoice_End_Date = CDate(Worksheets("Despatch Template").Cells(17, "G").Value)
Sheets("Despatch Template").Select
MsgBox IsDate(Invoice_End_Date)
MsgBox IsDate(Invoice_Start_Date)
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
ActiveSheet.PivotTables("PivotTable1").PivotFields("DESPATCH
DATE").ClearAllFilters
ActiveSheet.PivotTables("PivotTable1").PivotFields("DESPATCH
DATE").PivotFilters.Add2 _
Type:=xlDateBetween, Value1:=CLng(Invoice_Start_Date),
Value2:=CLng(Invoice_End_Date)