title: VBA for aligning the pivot table
body: <p>I am using an VBA to generate the Pivot Table.</p>
  
  <p>I wanted to Center align my values in the Pivot table, I used the follwing line, in my code, I am getting object required error. </p>
  
  <p>I researched in net, and everywhere it is the same, that we use</p>
  
  <blockquote>
    <p>DataLabel.HorizontalAlignment = xlCenter</p>
  </blockquote>
  
  <p>Below is the code, i am using to generate my Pivot table and trying to align the data values in the cell Center, Could someone suggest, where i am going wrong and how i could correct it. </p>
  
  <pre><code>Sub sum2017()
  Dim ws9 As Worksheet
  Dim pc9 As PivotCache
  Dim pt9 As PivotTable
  Dim ct9 As Integer
  Set ws9 = Sheets("Sum2017")
  Set pc9 = ActiveWorkbook.PivotCaches.Create(xlDatabase, "'Result'!R1C1:R1048576C6")
  Set pt9 = pc9.CreatePivotTable(ws9.Range("A3"))
  pt9.AddDataField pt9.PivotFields("Overdue"), "Sum of Overdue", xlSum
  pt9.AddDataField pt9.PivotFields("OK"), "Sum of OK", xlSum
  pt9.AddDataField pt9.PivotFields("Total"), "Sum of Total", xlSum
  pt9.AddDataField pt9.PivotFields("Overdue %"), "Sum of Overdue %", xlSum
  pt9.AddDataField pt9.PivotFields("OK %"), "Sum of OK %", xlSum
  ws.pt9.PivotSelect "Sum of overdue", xlDataOnly
  DataLabel.HorizontalAlignment = xlCenter
  
  End Sub
  </code></pre>