title: How do I iterate through a pivot table slicer excluding items with no data?
body: <p>I'm working on a macro that will loop through a pivot table slicer saving each page as a PDF while I do it. The only problem is the code is including slicer items that have no data (i.e. I've got 100 employees but only 40 have data and I'm still getting 100 pdfs with blanks on 60 of them). Is there a way to only loop through slicer items that are visible/have data? My code is below!</p>
  <pre><code>    Sub PowerPivotLoopSlicerPrintPDF()
  Dim sC As SlicerCache
  Dim SL As SlicerCacheLevel
  Dim sI As SlicerItem
  Dim c As Long
  
  Set sC = ActiveWorkbook.SlicerCaches(&quot;Slicer_Employee_ID1&quot;) 
  Set SL = sC.SlicerCacheLevels(1)
  c = 1 
  
  
  'LOOP THROUGH SLICER
  Do While c &lt;= sC.SlicerCacheLevels.Item.Count + 1  
      For Each sI In SL.SlicerItems
          If sI.Selected = True Then
          SlicerverdiIndex = c
      Exit For
          End If
      Next sI
  
  Dim FName           As String
  Dim FPath           As String
  
  
  FPath = &quot;FILE PATH HERE&quot;
  FName = Range(&quot;C4&quot;) &amp; &quot;-&quot; &amp; Range(&quot;C6&quot;)
  
  'Define WHAT to print and how to build file name
  ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
  FPath &amp; &quot;\&quot; &amp; FName &amp; &quot;.pdf&quot;, Quality:=xlQualityStandard, _
  IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
  False
  
  If SlicerverdiIndex = 1 Then
      SlicerverdiIndex = sC.SlicerCacheLevels.Item.Count + 1
  End If
  sC.VisibleSlicerItemsList = SL.SlicerItems(SlicerverdiIndex - 1).Name
  
  c = c + 1
  
  Loop
  
  End Sub
  </code></pre>