VBA code to loop through all options within a single slicer and print individual reports for each

lorbieckit

New Member
Joined
Dec 20, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I have a single pivot table slicer that contains 39 different last names. When I click on a last name it populates a dashboard with that athletes testing metrics. My goal is to create a VBA code that will loop through all 39 athletes and print individual reports for each to my default printer in a single action. I want to be able to attach this code to a print button on the dashboard.

I know this should be relatively easy as I can find bits and pieces of code to support this but am struggling to put it all together. Any help is appreciated!
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try this macro - assign it to your print button.

VBA Code:
Public Sub Print_Report_for_each_Slicer_Item()

    Dim slCache As SlicerCache
    Dim slItem As SlicerItem, slMatch As SlicerItem
    
    Set slCache = ThisWorkbook.SlicerCaches(1)
    
    'Select each slicer item and print active sheet
    
    For Each slItem In slCache.SlicerItems
        slCache.ClearManualFilter
        For Each slMatch In slCache.SlicerItems
            If slItem.Name = slMatch.Name Then slMatch.Selected = True Else: slMatch.Selected = False
        Next
        ActiveSheet.PrintOut
    Next
    
    slCache.ClearManualFilter
            
    MsgBox "Done"
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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