Stop slicer loop when no data present/greyed out

cc1987

New Member
Joined
Mar 4, 2016
Messages
18
I have a loop which goes through options in a slicer and prints out a report for each one. Is there a way to add a stop or skip command if there is no data present and the slicer option is greyed out as shown in the image?
Annotation.png


Code:
VBA Code:
 'This VBA will loop through your Power Pivot slicer and print the results to PDF.
'To get it working change slicer name and storage location in below VBA.
Public Sub PrintToPDF()
Dim sC As SlicerCache
Set sC = ActiveWorkbook.SlicerCaches("Slicer_Player")
Dim folderPath As String

folderPath = Application.ActiveWorkbook.Path

  'This reminds the user to only select the first slicer item
    If sC.VisibleSlicerItems.Count <> 1 Or sC.SlicerItems(1).Selected = False Then
      MsgBox "Please Select First Athlete In Slicer"
      Exit Sub
   End If


For i = 1 To sC.SlicerItems.Count

    'Do not clear ilter as it causes to select all of the items (sC.ClearManualFilter)

    sC.SlicerItems(i).Selected = True
    If i <> 1 Then sC.SlicerItems(i - 1).Selected = False


    'Debug.Print sI.Name
    'add export to PDF code here
    With Sheet3.PageSetup

    .PrintArea = Sheet3.Range("A1:Q289" & lastRow).Address

    .FitToPagesWide = 1
    .FitToPagesTall = 3

    End With

    Sheet3.Range("AA1") = sC.SlicerItems(i).Name

   'This prints to C directory, change the path as you wish

   Sheet3.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    folderPath & "/Reports/" & Sheet3.Range("AA1").Text & "_" & _
        Format(Date, "dd mmm yyyy") & ".pdf", Quality:= _
    xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
    OpenAfterPublish:=False

Next

End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,214,918
Messages
6,122,243
Members
449,075
Latest member
staticfluids

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