VBA - Slicer selection (via loop) is very slow.

barowan

New Member
Joined
Mar 6, 2014
Messages
15
Greetings,

I'm using excel2013

I'm using below code to select one specific item from the slicer (Slicer_Naam) this depends on the input from a dropdown list. (There's +600 options, that's why I want to use the dropdownlist with autoadding to be much quicker than the slicers) - If I understand the code right (I adjusted pieces from stuff I found online, I never learned how to code properly) it selects all options in the slicer menu en then checks them one by one untill it has a match with the values in the dropdownlist. Because there's over 600+ options this process takes +- 3 minutes. quite a hassle, because I would like to make a dashboard out of it.

My question:
Is there any way to fasten up the code? I searched the web, to try to find some code that makes the slices select the option based on a cell value (their all using letters, not numerical - they're names) but I couldn't find a solution without using loops. - I feel there's a (much) more effective, efficient way to do this.

Code:
Sub SelPg()<code>Dim a As Variant
Dim n As Integer
Dim s As String
Dim i As Integer
Dim m As Long
Dim rr As Integer
Application.Calculation = xlCalculationManual

Application.ScreenUpdating = False

Application.DisplayStatusBar = False

Application.EnableEvents = False

ActiveSheet.DisplayPageBreaks = False


With ActiveWorkbook
    With .Sheets("Lijsten_Werkblad_Droplist").Range("Tabel1")
        rrr = .Rows.Count
        ReDim a(rrr, 1)
        a = .Value
    End With
    
    
    With .SlicerCaches("Slicer_Naam")
        .ClearManualFilter
    With .Slicers("Naam")
        With .SlicerCache
            .ShowAllItems = True
            n = .SlicerItems.Count
            For i = 1 To n
                With .SlicerItems(i)
                    For m = 1 To rrr
                    If .Name = a(m, 1) Then GoTo gimp
                    Next m
                    .Selected = False
gimp:           End With
            Next i
        End With
   End With
   End With

   
End With

Application.Calculation = xlCalculationAutomatic

Application.ScreenUpdating = True

Application.DisplayStatusBar = True

Application.EnableEvents = True

ActiveSheet.DisplayPageBreaks = True
 </code>End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Forum statistics

Threads
1,214,925
Messages
6,122,303
Members
449,078
Latest member
nonnakkong

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