title: Macro To Change Pivot Table Filters
body: <p>My goal is to change the filter of  3 pivot tables, all with the same field with the click of a button attached to a macro.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    Dim pickedDate As String
      Dim shift As String
  
       pickedDate = Worksheets("Report").Range("C1").Value
      shift = Worksheets("Report").Range("C2").Value
  
      Worksheets("Report").PivotTables("PivotTable2").PivotCache.SourceData = Worksheets("Fullness").Range("A1").CurrentRegion.Address(, , xlR1C1, True)
      Worksheets("Report").PivotTables("PivotTable3").PivotCache.SourceData = Worksheets("Backed").Range("A1").CurrentRegion.Address(, , xlR1C1, True)
      Worksheets("Report").PivotTables("PivotTable4").PivotCache.SourceData = Worksheets("Hoist").Range("A1").CurrentRegion.Address(, , xlR1C1, True)
  
  
      For Each PT In ActiveSheet.PivotTables
          PT.PivotFields("Date").CurrentPage = CDate(pickedDate)
          PT.PivotFields("Shift").CurrentPage = shift
      Next
  </code></pre>
  
  <p>However when I get to my loop for the pivot tables, I get the error on <code>PT.PivotFields("Date").CurrentPage = CDate(pickedDate)
  </code> :</p>
  
  <p><code>Run time error 1004</code> </p>
  
  <p><code>Application  Defined or Object Defined Error</code></p>
  
  <p>I've verfied the source data for the tables is updated correctly.</p>
  
  <p>I've tried not using the loop, and doing it manually like</p>
  
  <p><code>Worksheets("Report").PivotTables("PivotTable4").PivotFields("Date").CurrentPage = CDate(pickedDate)</code></p>
  
  <p>for each table, and it only works for one of the tables, my <code>PivotTable3</code>.</p>
  
  <p>Even more curiously, when I comment out my code to change the date, and use either way (the loop or the manual change for the 3 tables) for the shift change it works perfectly with no error. </p>
  
  <p>I've verfied the name of my pivot tables, that's not the issue. The name of the field I'm trying to change appears correct as well- it works for one of the tables and I've copied and pasted that cell "Date" into the others even.</p>
  
  <p>What am I missing?</p>