title: Filtering Pivot Slicer using a range of values
body: <p>I have a pivot table that is filtered by a date filed pivot slicer.
  On another sheet i have a 12 month date range example from cell A1:A12.
  I have code that loops through the slicer and tries to match whats in the slicer compared to the range. Ideally i would want the slicer to then only select the values that exist within the range A1:A12. The code below runs but selected everything once the loop has terminated.</p>
  
  <p>Any ideas? </p>
  
  <pre><code>Sub DateSelect()
  
  Dim ws As Worksheet
  Dim i As Integer, iLookupColumn As Integer
  Dim sl As SlicerCache
  Dim sDate As String
  Set sl = ThisWorkbook.SlicerCaches("Slicer_Month_and_Year")
  
  Set ws = ThisWorkbook.Sheets("Macro")
  For i = 1 To sl.SlicerItems.Count
      sDate = sl.SlicerItems(i).Name
      If IsError(Application.Match(sDate, ws.Range(ws.Cells(1, 14), ws.Cells(13, 14)), 0)) Then
          ThisWorkbook.SlicerCaches("Slicer_Month_and_Year").SlicerItems(i).Selected = False
      Else
          ThisWorkbook.SlicerCaches("Slicer_Month_and_Year").SlicerItems(i).Selected = True
      End If
  Next i
  
  
  End Sub 
  </code></pre>