Excel VBA Debug: I need a From and To date/time filter on a pivot table.

Job ID: 32625114

Budget: $25 – $150 AUD

I have been trying to set up a filter in an excel spreadsheet so I can extract a start date and end date from my spreadsheet, then filter the results from a list of values based on the start and end dates.

Whatever I try I end up with an error in my final step:

ActiveSheet.PivotTables("ValPivot").PivotFields("DateTimeVal").PivotFilters.Add _
Type:=x1Between, _
Value1:=Start_DateTimeVal, _
Value2:=End_DateTimeVal

I have tried using a variable as a Double, Long and Date format - it gives me different errors but still doesn't work. Attached is a sample of the type of data, the pivot tables and my sample code in an .xlsm workbook.

I have two separate approaches - one pivot table using Date format and the other using Double. I only need one of them to work.

Errors I get are Run Time 5; or Run Time 1004; or
Related categories: Visual Basic Data Processing Excel