title: VBA Code to Control Multiple Pivot Table Slicers
body: <p>I'm trying to set-up some VBA code that will allow me to control multiple pivot tables (and data sources) with 1 slicer.</p>
  
  <p>In the past, I have only needed to implement VBA code that controls 1 additional slicer, but now I am trying to set-it up to control 2 slicers and am running into issues.</p>
  
  <p>Here is my code that I used in the past for controlling 1 slicer:</p>
  
  <p>As a module:</p>
  
  <pre><code>Public PrevCat As String
  </code></pre>
  
  <p>In ThisWorkbook:</p>
  
  <pre><code>Private Sub Workbook_Open()
      PrevCat = Sheet27.Range("O5").Value
  End Sub
  </code></pre>
  
  <p>Primary code:</p>
  
  <pre><code>Option Explicit
  
  Private Sub Worksheet_Calculate()
  Application.ScreenUpdating = False
  
  
  Dim pt As PivotTable
  Dim Field As PivotField
  Dim NewCat As String
  
  NewCat = Sheet27.Range("O5").Value
  
      If NewCat &lt;&gt; PrevCat Then
          Application.EnableEvents = False
          Set pt = Sheet27.PivotTables("Pivot Match 2")
          Set Field = pt.PivotFields("Region")
          With Field
              .ClearAllFilters
              On Error Resume Next
              .CurrentPage = NewCat
              On Error GoTo 0
          End With
          pt.RefreshTable
          PrevCat = NewCat
          Application.EnableEvents = True
      End If
  Application.ScreenUpdating = True
  
  End Sub
  </code></pre>
  
  <p>Like I said, this code works perfectly for controlling 1 additional slicer. However, I need the code to control 2 slicers. All i did was add an additional If statement, but it doesn't seem to work:</p>
  
  <pre><code>Option Explicit
  
  Private Sub Worksheet_Calculate()
  Application.ScreenUpdating = False
  
  
  Dim pt As PivotTable
  Dim Field As PivotField
  Dim NewCat As String
  
  NewCat = Sheet27.Range("O5").Value
  
      If NewCat &lt;&gt; PrevCat Then
          Application.EnableEvents = False
          Set pt = Sheet27.PivotTables("Pivot Match 2")
          Set Field = pt.PivotFields("Region")
          With Field
              .ClearAllFilters
              On Error Resume Next
              .CurrentPage = NewCat
              On Error GoTo 0
          End With
          pt.RefreshTable
          PrevCat = NewCat
          Application.EnableEvents = True
      End If
  
      If NewCat &lt;&gt; PrevCat Then
          Application.EnableEvents = False
          Set pt = Sheet27.PivotTables("Pivot Match 3")
          Set Field = pt.PivotFields("Region")
          With Field
              .ClearAllFilters
              On Error Resume Next
              .CurrentPage = NewCat
              On Error GoTo 0
          End With
          pt.RefreshTable
          PrevCat = NewCat
          Application.EnableEvents = True
      End If
  
  
  Application.ScreenUpdating = True
  
  End Sub
  </code></pre>
  
  <p>Any ideas on how i can get this to work?</p>