title: Excel VBA - Change date filter of a pivottable
body: <p>I have a pivottable on my sheet and I'm trying to add a date filter:</p>
  
  <pre><code>Private Sub foo()
  
  Dim MyDate
  MyDate = #1/27/1993#
  Worksheets("Timeline").PivotTables("PivotTable7").PivotFields("EndDateFormatted").PivotFilters.Add Type:=xlBetween, Value1:=MyDate, Value2:=MyDate
  
  End Sub
  </code></pre>
  
  <p>How ever this results in an "invalid procedure call or argument" error. What am I doing wrong?</p>
  
  <p>Update:
  thx luke_t, now I know that I have to use xlDateBetween.
  Now my code looks like:</p>
  
  <pre><code>Private Sub foo()
      Dim d As Date
      Dim dd As Date
  
      d = DateSerial(2016, 1, 1)
      dd = DateSerial(2016, 1, 2)
      Worksheets("Timeline").PivotTables("PivotTable7").PivotFields("EndDateFormatted").PivotFilters.Add Type:=xlDateBetween, Value1:=d, Value2:=dd
  End Sub
  </code></pre>
  
  <p>Now it says "the date you entered is not a valid date" (1004). </p>