title: VBA Excel Add A Values Field
body: <p>I am trying to add a values field to an existing <code>PivotTable</code>. I get the pivot table I want, but after it gets done compiling I get a Run-time error </p>
  
  <blockquote>
    <p>"1004" Application-defined or object-defined error</p>
  </blockquote>
  
  <p>at the following line : <code>pt.AddDataField pt.PivotFields("Hours"), SumofHours, xlSum</code></p>
  
  <p>Here is my code:</p>
  
  <pre><code>Workbooks.Open "file path..."
  Worksheets("Mo Pivot Tbl").Activate
  
  Set pt = ActiveSheet.PivotTables("PivotTable1")
  pt.AddDataField pt.PivotFields("Hours"), SumofHours, xlSum
  </code></pre>