title: VBA to connect slicers (looking for improvements to code)
body: <p>I finally found a code that will connect slicers with different caches on pivot table update. Basically when the value of slicer1 changes, it will change slicer2 to match slicer1 thus updating any pivot table connected to the second slicer.</p>
  
  <p>I've added <code>.Application.ScreenUpdating</code> and <code>.Application.EnableEvents</code> in an attempt to speed up the macro but it's still laggy and causes Excel to become unresponsive.</p>
  
  <p>Is there a more direct way of coding this or are there any potentially volatile lines in here causing Excel to fry it's brain?</p>
  
  <pre><code>Private Sub Worksheet_PivotTableUpdate _
      (ByVal Target As PivotTable)
  Dim wb As Workbook
  Dim scShort As SlicerCache
  Dim scLong As SlicerCache
  Dim siShort As SlicerItem
  Dim siLong As SlicerItem
  
  Application.ScreenUpdating = False
  Application.EnableEvents = False
  On Error GoTo errHandler
  Application.ScreenUpdating = False
  Application.EnableEvents = False
  
  Set wb = ThisWorkbook
  Set scShort = wb.SlicerCaches("Slicer_Department")
  Set scLong = wb.SlicerCaches("Slicer_Department2")
  
  scLong.ClearManualFilter
  
  For Each siLong In scLong.VisibleSlicerItems
      Set siLong = scLong.SlicerItems(siLong.Name)
      Set siShort = Nothing
      On Error Resume Next
      Set siShort = scShort.SlicerItems(siLong.Name)
      On Error GoTo errHandler
      If Not siShort Is Nothing Then
          If siShort.Selected = True Then
              siLong.Selected = True
          ElseIf siShort.Selected = False Then
              siLong.Selected = False
          End If
      Else
          siLong.Selected = False
      End If
  Next siLong
  
  exitHandler:
      Application.ScreenUpdating = True
      Application.EnableEvents = True
      Exit Sub
  
  errHandler:
      MsgBox "Could not update pivot table"
      Resume exitHandler
  Application.ScreenUpdating = True
  Application.EnableEvents = True
  End Sub
  </code></pre>
  
  <p>original code found on <a href="http://www.contextures.com/excelslicersupdatevba.html" rel="nofollow noreferrer">Contextures</a></p>
  
  <p>Thanks for any advice as always.</p>
  
  <p><a href="https://stackoverflow.com/questions/39376238/macro-to-change-multiple-slicer-values/39599114#39599114">link to original inquiry:</a> </p>