title: How to use getpivotdata when pivot table datafield has a subheader
body: <p>I'm trying to use getpivotdata to copy certain specific pivot table data to the data sheet. I am able to do it if there are no subheaders. However when there are subheaders i run into problems running the code.</p>
  
  <p>i've tried many different methods but to no avail please help. I believe that i'm missing out something in the bracket for getpivotdata. Please take a look at the code</p>
  
  <p><a href="https://i.stack.imgur.com/Tw2GI.png" rel="nofollow noreferrer">Error i get from Damian's Answer</a></p>
  
  <p><a href="https://i.stack.imgur.com/5z7Ce.png" rel="nofollow noreferrer">Sample Data</a></p>
  
  <p><a href="https://i.stack.imgur.com/UVwwx.png" rel="nofollow noreferrer">Picture of Pivot Table</a></p>
  
  <p>It works when i don't include the subheader.</p>
  
  <pre><code>Dim PT As PivotTable
  
      Set PT = Sheet2.PivotTables("PivotTable2")
  
      Range("C28").Value = PT.GetPivotData("Profit", "Region", "2", "Department", "107").Value
  </code></pre>
  
  <p>It doesn't work when i include the subheader as shown below. It will give me error 1004 (Application Defined or Object Defined Error)</p>
  
  <pre><code>Dim PT As PivotTable
  
      Set PT = Sheet2.PivotTables("PivotTable2")
  
      Range("C28").Value = PT.GetPivotData("Profit", "Region", "2", "Department", "107", "Staff", "Jim").Value
  </code></pre>
  
  <p>I expect it to display the data under Staff Jim in Cell C28 , but right now i can only get the data of all the staff under the same department of 107.</p>