Hi guys, I have this excel file with some data in sheet1 (this data is collected running a Macro) and I need to create multiple pivot tables and pivot charts embedded with the data in Sheet1 (the idea is that the pivot tables and the charts change with respect to the data in sheet1), but I am very lost, I am trying to write a code to create a single Pivot Table but It did not work and also I do not know if that is the best way to create multiple tables and charts.
The code I was using to create a pivot table is the following, but gives me an error in "Source Data"
Maybe someone can help me with some advice or help, thank you.
Sub CreatePivotTable() Dim pc As PivotCache Dim ws As Worksheet Dim pt As PivotTable Set pc = ThisWorkbook.PivotCaches.Create( _ SourceType:=xlDatabase, _ SourceData:=wsSheet1.Name & "!" & wsSheet1.range("A1").CurrentRegion.Address, _ Version:=xlPivotTableVersion16) Set ws = Worksheets.Add ws.Name = "PivotTables" range("A3").Select Set pt = pc.CreatePivotTable( _ TableDestination:=ActiveCell, _ TableName:="FirstPivotTable") pt.AddFields _ RowFields:="Inspector", _ RowFields:="Classification", _ ColumnFields:="Classification", _ PageFields:="Classification for each Inspector" pt.AddDataField _ field:=pt.PivotFields("Run time"), _ Function:=XlConsolidationFunction.xlCount pt.DataFields(1).NumberFormat = "0.00" End Sub