Filter a pivot slicer on dates - working, but is there a quicker way?!

dancing-shadow

New Member
Joined
Dec 4, 2011
Messages
24
Hello,

I have the below bit of code within a larger piece of code which is working as intended - looping through each slicer item, and selecting/deselecting if the date meets the specified criteria.
My issue is that as my data increases, there are more and more dates to loop through, and it's obviously taking longer and longer to complete. I tried adding in the xlCalculationManual/Automatic, thinking that would stop the pivots updating after each individual date is dealt with, but it hasn't helped at all. I'm wondering if there is any other way at all I can make this run faster? If I stop the macro at the first Application.Calculation, manually select/deselect the slicer dates myself and resume the code from the second Application.Calculation, the whole code in it's entirety takes around 3-5 mins to run. By letting it cycle through the slicer items itself it's taking upwards of an hour... I can't can't fathom quite why it takes so long to look at a date, determine if it meets the criteria, deal with it and move on.

For some background info, I cannot let the pivots unfilter all dates and re-filter on the dates between x and y criteria, as the layout of the pivots means there is not enough room to allow the pivot to expand before collapsing again - basically on the left there is a pivot for daily totals, and right next to it on the right is a pivot for monthly totals. There are around 15 of these pairs of pivots altogether of varying sizes (rows), and I cannot amend the layout due to client specifications - hence using the slicer, as this deselects some dates before reselecting others so the total amount of dates selected never exceeds 30.


Code:
Dim today As Date
Dim startdte As Date


today = Date
startdte = today - 30


Application.Calculation = xlCalculationManual


    For Each item In ActiveWorkbook.SlicerCaches("Slicer_due_abs").SlicerItems
        If item.Name = "(blank)" Then
            item.Selected = False
        ElseIf item.Name >= startdte And item.Name <= today Then
                item.Selected = True
                    Else
                item.Selected = False
            End If
    
    Next item
    
Application.Calculation = xlCalculationAutomatic
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top