title: Arrange Pivot Columns Using Record Macro
body: <p>I'm a macro noob, however I have quite a bit of experience recording macros and manipulating code to make adjustments. Today I have an issue I need to solve. I am trying to record a macro to reorganize the order of the columns within a pivot. I have tried recording a macro while I move the values around in the PivotTable Fields form, as well as clicking the Value field in the PivotTable Fields section and selecting "Move to End". Both are not working and I'm getting left with an error, "Run-time error '5': Invalid procedure call or argument. Below is the code from the recording for reference.</p>
  
  <p><strong>How can I properly reorganize the columns of a pivot using a macro or macro recording?</strong></p>
  
  <p>Thanks,
  Steve</p>
  
  <hr>
  
  <pre><code>Sub PivotColumnArrange()
  '
  ' PivotColumnArrange Macro
  ' Arranges Pivot Columns In Proper Order
      Range("F3").Select
      ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
          "PivotTable2").PivotFields("Sum of AverageCPC"), "Sum of AverageCPC", xlSum
      ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
          "PivotTable2").PivotFields("Sum of AveragePos."), "Sum of AveragePos.", xlSum
      ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
          "PivotTable2").PivotFields("Sum of Conversions"), "Sum of Conversions", xlSum
      ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
          "PivotTable2").PivotFields("Sum of CPA "), "Sum of CPA ", xlSum
      ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
          "PivotTable2").PivotFields("Sum of CPA "), "Sum of CPA ", xlSum
      ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
          "PivotTable2").PivotFields("Sum of CVR "), "Sum of CVR ", xlSum
      ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
          "PivotTable2").PivotFields("Sum of CTR"), "Sum of CTR", xlSum
  End Sub
  </code></pre>