title: Creating a Pivot Table in VBA : Run Time Error '1004' (Unable to get the PivotTables property of Worksheet class)
body: <p>I am using Excel 2010 and I am using the following VBA code to create Pivot table :-</p>
  
  <pre><code>Sub addFields()
  
    With ActiveSheet.PivotTables(1)
  
      With .PivotFields("Name")
        .Orientation = xlRowField
        .Position = 1
      End With
  
      With .PivotFields("Location")
        .Orientation = xlPageField
        .Position = 1
      End With
  
     .AddDataField ActiveSheet.PivotTables(1).PivotFields("Order Amount"), _
       "Sum of Amount", xlSum
  
    End With
  
  End Sub
  </code></pre>
  
  <p>Following is the data on <em>Sheet1</em> where I want to create a Pivot Table.</p>
  
  <pre><code>Name     Order Amount   Location
  Grace    1200000        New York
  Tom      2000000        New York
  Madhuri  5000000        Delhi
  Hari     6000000        Delhi
  Raj      7000000        Delhi
  Victoria 8000000        New York
  </code></pre>
  
  <p>But I am getting a:</p>
  
  <blockquote>
    <p>Run Time Error 1004 : Unable to get PivotTables property of Worksheet class. </p>
  </blockquote>
  
  <p>Can anyone please suggest on this?</p>