大家早上好,
我正在尝试使用枢纽分析表创建两个图表。但是,两个图表完全相同,而图表的columnfield
不同。
我在两个图表上都具有相同的columnfield
我希望我足够清楚谢谢您的时间和帮助
这是我创建表和图表的宏部分。
Sub tracer ()
Set Table = Cache.CreatePivotTable(TableDestination:=graphe_clos.Cells(1, 1), TableName:="Terminator")
Set Table1 = Cache.CreatePivotTable(TableDestination:=graphe_clos.Cells(25, 1), TableName:="Terminator2")
With graphe_clos.Shapes.AddChart(204, xlColumnClustered).Chart
.ClearToMatchStyle
.ChartStyle = 257
end with
With Table.PivotFields("Tranches")
.Orientation = xlRowField
.Position = 1
End With
With Table.PivotFields("Evt F")
.Orientation = xlColumnField
.Position = 1
.PivotItems("(blank)").visible = False
End With
With graphe_clos.Shapes.AddChart(204, xlColumnClustered).Chart
.ClearToMatchStyle
.ChartStyle = 257
end with
With Table1.PivotFields("Tranches")
.Orientation = xlRowField
.Position = 1
End With
With Table1.PivotFields("Evt P")
.Orientation = xlColumnField
.Position = 1
.PivotItems("(blank)").visible = False
End With
End Sub
答案 0 :(得分:0)
这很可能是因为使用/共享了相同的缓存。您可以尝试以下操作:
Set pvtCache = wbSource.PivotCaches.create(SourceType:=xlDatabase, SourceData:=YourDataRngStr) 'data/table range, something like "A1:E100"
Set pvtCache = wbSource.PivotCaches.create(SourceType:=xlDatabase, SourceData:=YourDataRngStr) 'data/table range, something like "A1:E100"
Set Table = pvtCache.CreatePivotTable(TableDestination:=graphe_clos.Cells(1, 1), TableName:="Terminator")
Set Table1 = pvtCache.CreatePivotTable(TableDestination:=graphe_clos.Cells(25, 1), TableName:="Terminator2")
谢谢