title: Run-time error '1004' when using macro to change pivot field.. but only with some values
body: <p>I'm using a code to change one pivot field of just one pivot according to the value of a cell (the cell contain text, is not a reference to another cell). The strangest thing is that it works for almost all the values I have but not with all of them...</p>
  
  <p>The code is the following:</p>
  
  <pre><code>Private Sub Worksheet_Change(ByVal Target As Range)
  If Not Application.Intersect(Target, Sheets("Sheet2").Range("D1")) Is Nothing Then
  Sheets("Sheet2").PivotTables("PivotTable1").PivotFields("Field1"). _
  ClearAllFilters
  Sheets("Sheet2").PivotTables("PivotTable1").PivotFields("Field1").CurrentPage _
  = Sheets("Sheet2").Range("D1").Value
  End If
  End Sub
  </code></pre>
  
  <p>the debug says the problem is the following line </p>
  
  <pre><code>Sheets("Sheet2").PivotTables("PivotTable1").PivotFields("Field1").CurrentPage _=      Sheets("Sheet2").Range("D1").Value
  </code></pre>
  
  <p>and the error says : " Run-time error '1004' Application-defined or object-defined error".</p>
  
  <p>Can someone please help me? Thank you very much!</p>
  
  <p>p.s. the value of the cell containing the text that is used to change the pivot field is changed by another macro that takes the value from a pivot so the value are existing and the format is the same for all the values so I can't figure out what is the problem...</p>