
Worksheets.Add After:=ActiveSheet ' to add a new worksheetĪctiveSheet.Name = "pvsheet" ' to rename the worksheet into "pvsheet" On Error GoTo 0 Worksheets("pvsheet").Delete 'to delete the exisiting pivot table in the worksheet To delete the previous pivot table sheet and create a new sheet to insert the pivot table. This will help to avoid confusions on which table the source data to be plotted. Step 7: The next step is to delete if there is any pivot table already created. This can be any row or column, so there are chances to be a number of rows and columns beyond the integer data type limit. Step 6: You need two more variables as long datatype to indicate the last used row and column for pivot table creation. So the datasheet variable is declared as pdsheet. Step 5: You need a similar variable to use the datasheet, which should contain the data you want to plot as a pivot table. Step 4: A worksheet needs to insert the pivot table which you need to create. In the pivot table, the source data is spread as rows and columns so to point to a particular range we need a variable. Step 3: The data is within the worksheet and should specify a range to hit the cell that you need. Declare the variable pvcache for pivot cache. Before creating a pivot table, declare a pivot cash variable. Step 2: To keep the data files, we need a pivot cache to declare the source of the data. Declare a function and pivot table object. Create an object for the pivot table this object will be used to point to the pivot table on further codes.

Step1: Pivot table should consider as a reference object. You can download this VBA Pivot Table Excel Template here – VBA Pivot Table Excel Template
