title: VBA to collapse/expand all rows in a PivotTable which includes a Filter
body: <p><strong>Excel:</strong></p>
  <pre><code>   |      A       |       B       |       C       |     D    |
  ---|--------------|---------------|---------------|----------|---
  1  |    Channel   |    Category   |    Product    |   Sales  |
  ---|--------------|---------------|---------------|----------|---
  2  |    Online    |    Apparel    |   Product A   |    500   |
  3  |    Online    |    Apparel    |   Product A   |    400   |
  4  |    Retail    |    Shoes      |   Product A   |    600   |
  5  |    Retail    |    Apparel    |   Product B   |    300   |
  6  |    Retail    |    Beauty     |   Product C   |    100   |
  7  |    Online    |    Shoes      |   Product C   |    200   |
  8  |    Retail    |    Apparel    |   Product D   |    450   |
  9  |    Retail    |    Beauty     |   Product D   |    700   |
  10 |    Online    |    Beauty     |   Product D   |    250   |
  11 |              |               |               |          |
  </code></pre>
  <p><strong>PivotTable:</strong></p>
  <p><a href="https://i.stack.imgur.com/gzO3i.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gzO3i.png" alt="enter image description here" /></a></p>
  <hr />
  <p>On the above PivotTable I want to run a VBA to expand/collapse all the rows. <br>
  I was able to do this with this code:</p>
  <pre><code>Sub PivotTable_Collapse()
  Sheet1.PivotTables(&quot;PivotTable1&quot;).PivotFields(1).ShowDetail = True
  End Sub
  </code></pre>
  <p>However, after I implemented the <code>filter Channel</code> into the PivotTable the VBA does not expand/collapse the rows anymore. <br></p>
  <p>How can I solve this issue?</p>