I'm trying to fix a 1004 error in the following code. Also, please note that I have removed the non-essential stuff like my own comments/debugs and the rest of the code after the error. But I have left in the comments from the guy who wrote the script.
Background: What this code is supposed to do is reset a time period filter for some pivottables that retrieve accounting data to do Percentage Of Completion calculations. However, since a few weeks we have been getting a 1004 error and the code does not run anymore.
Attempts so far: So what have I tried/looked at to fix this? I have tried passing different start and end date values to see if this could fix it but that did not help. I have also examined the reports that the cache has been connected to but this didn't help me get an understanding of the problem either. Because none of the pivot tables or queries are showing any errors. The rest of my efforts are best summed up as reading up on all things pivot table and checking forums for similar problems.
Thanks in advance for your help.
' This is a subroutine to adjust the selections in the timeline slicers for the pivot data.
Dim startDate As Date
Dim endDate As Date
Dim cache As SlicerCache
' Startdate for all slicers is the min cal date
startDate = ActiveWorkbook.Sheets("Helpers").Range("MinCalDate").Value
' Set the end date to the last date of this period
If ActiveWorkbook.Sheets("Helpers").Range("PeriodStart").Value > Date Then
endDate = DateSerial(Year(Date), Month(Date) + 1, 0)
Else
endDate = ActiveWorkbook.Sheets("Helpers").Range("PeriodEnd").Value
'Set slicer 1 End date as slicer selection instead
End If
' Transaction dates are between the earlies start date and end date
Set cache = ActiveWorkbook.SlicerCaches("Timeline_TRANSACTIONDATE")
ActiveWorkbook.SlicerCaches("Timeline_TRANSACTIONDATE").TimelineState.SetFilterDateRange startDate, endDate
.....
End Sub
There are 2 kinds of slicers.
xlslicerandxltimeline. If you use.TimelineState.SetFilterDateRangeonxlslicerthen you will get an error.You will have to use an
xltimelineslicer for your purpose and then your code will work.Here is an example