This video details the VBA code needed to create a PivotTable. Get the code here https://www.bluepecantraining.com/portfolio/excel-vba-how-to-create-a-pivottable-with-excel-macro/

The video follows these steps for creating the PivotTable:

1) Create the Pivot Cache
2) Create the PivotTable
3) Define fields for row, column, filter and data areas of the Pivot report
4) Format the data in the PivotTable.
------------------------