MrExcel Code to loop through Slicers not working

TopCatz

New Member
Joined
Jan 20, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi There
Im trying to follow along with MrExcel code to loop through slicers and produce PDF files, however Im getting error on the first section of the Code - Please see below the code I used from MrExcel.

VBA Code:
Sub DoAllCombinations()
    Dim sc1 As SlicerCache
    Dim sc2 As SlicerCache
    Dim SI As SlicerItem
    Dim cell1 As Range
    Dim cell2 As Range
    Dim cell3 As Range
    
    ' These are the Slicer Names from the Slicer Settings Box
    Set sc1 = ThisWorkbook.SlicerCaches("Slicer_Account_Name")
    Set sc2 = ThisWorkbook.SlicerCaches("Slicer_Chart_Format4")
    sc1.ClearAllFilters
    sc2.ClearAllFilters
    Ctr = 1
    
    'Off to the right, build static lists of all Slicer Items
    NextCol = ActiveSheet.UsedRange.Columns.Count + 2
    RememberCol = NextCol
    NextRow = 1
    For Each SI In sc1.SlicerItems
        Cells(NextRow, NextCol).Value = SI.Caption
        NextRow = NextRow + 1
    Next SI
    LastRow = NextRow - 1
    Cells(1, NextCol).Resize(LastRow, 1).Name = "SlicerItems1"
    NextRow = 1
    NextCol = NextCol + 1
    For Each SI In sc1.SlicerItems
        Cells(NextRow, NextCol).Value = SI.Caption
        NextRow = NextRow + 1
    Next SI
    LastRow = NextRow - 1
    Cells(1, NextCol).Resize(LastRow, 1).Name = "SlicerItems2"
    
    Application.ScreenUpdating = False
    
End Sub

It is erroring on the line 'For Each SI in scl.SlicerItems' with a Run-time error '1004': Application-defined or object defined error.
Hitting Debug, highlights the For Each line

Please let me know what I have done wrong as I can not move past this part to the rest of the code.

thank you!
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,215,077
Messages
6,122,992
Members
449,094
Latest member
masterms

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