title: Excel VBA: runtime error 13 - type mismatch while collapsing the pivotitems
body: <p>I am trying to collapse the pivot items through loop using VBA. Below is the code:</p>
  
  <pre><code>Dim oPI As PivotItems
  
  For Each oPI In ActiveSheet.PivotTables("PivotTable4").PivotFields("TAG").PivotItems
  oPI.ShowDetail = False
  Next oPI
  </code></pre>
  
  <p>I am getting Runtime error 13 - "Type mismatch" error. Not sure what is wrong with this code.
  Could anyone please let me know what changes to make?</p>