title: VBA Pivot Table Filter .ClearAllFilters without replacing data below
body: <p>I have a code to filter a pivot table to a range of dates no larger than 31 days. Since I know the length of the pivot table I have other data and information below the pivot table to work with. Problem is the data source has a much larger range of dates so when I use the <code>.ClearAllFilters</code> it wants to replace all of the data below before it filters to the correct range.  </p>
  
  <p>Here is my simple code:</p>
  
  <pre><code>Set pt = RepSheet.PivotTables("PivotTable1")
      pt.PivotFields("Date").ClearAllFilters
      pt.PivotFields("Date").PivotFilters.Add Type:=xlDateBetween, _
          Value1:=SelectedDate1, Value2:=SelectedDate2
  </code></pre>
  
  <p>I have tried the code below to set the filters all to <code>False</code> instead of clearing the filters but I just get an error when trying to set the filters.  </p>
  
  <pre><code>With pt.PivotFields("Date")
      For i = 1 To .PivotItems.Count - 1
          .PivotItems(.PivotItems(i).Name).Visible = False
      Next i
  End With
  </code></pre>
  
  <p>Any suggestions? I really don't want to put the data on top of the pivot table.</p>