title: VBA PivotItems Index Variable
body: <p>I am trying to loop through different years of data from a OLAP pivot table and for each year I have to drilldown to get the data I am looking for. Here is what the macro recorder gave me for 2013:</p>
  
  <pre><code>'This is the cell that has to be drilled down
  Range("A2").Select
  
  With ActiveSheet.PivotTables("PivotTable1").PivotFields("[Date].[YMD].[Year Name]") _
  
  .PivotItems("[Date].[YMD].[Year Name].&amp;[***2013***]").DrilledDown = True
  
  End With
  </code></pre>
  
  <p>[Date].[YMD] is the field name and [Year Name] is the source name.</p>
  
  <p>However I am trying to replace the &amp;[2013] with a variable "Yr" which will allow me to select and then drill down into each year.</p>
  
  <p>But I get the following message: "Unable to get the PivotItems property of the PivotField class"</p>
  
  <p>Is there a specific syntax for PivotItems Index? Are there limitations to using a variable to reference from an OLAP Pivot Table? I have tried defining Yr as a Double and also as a Variable but it didn't help..</p>
  
  <p>Thanks for any advice!!</p>