title: Use VBA to refresh pivot tables
body: <p>I am working on a project, where I dump data on a monthly basis in Sheet1. In my sheet analysis, I have three pivot tables summarizing this data using certain filter, which should remain unchanged even if the raw data changes. </p>
  
  <p>I use the following VBA code to update the pivot tables after the data dump.</p>
  
  <pre><code>Private Sub CommandButton1_Click()
  
  
  With ThisWorkbook.Worksheets("Analysis")
  
  .PivotTables("PivotTable1").RefreshTable
  .PivotTables("PivotTable2").RefreshTable
  
  End With
  
  Sheets("Output").Activate
  
  End Sub
  </code></pre>
  
  <p>The problem is, whenever I have a new data dump in Sheet 1 and then run the code, I get the following message: <em>There is already data in [Dokument1]Analysis. Do you want to replace it?</em> After this the output from the pivot tables is wrong and the supposedly static pivot filters are no longer there. </p>
  
  <p>I made sure that there is more than enough space between the pivot tables and there cannot be any overlaps. I have had this problem for a long time and do not know how to solve it, so any help is appreciated.</p>