vba - 使用两个不同的数据透视表拥有相同的图表信息
问题描述
大家早上好,
我正在尝试使用数据透视表创建两个图表。但是我有完全相同的两个图表,而columnfield
图表的不一样。我在两个图表上都有相同的columnfield
Evt F ,而不是图表 1上的Evt F和图表 2上的Evt P。数据透视表和图表在同一张表graphe_clos上。
我希望我足够清楚谢谢您的时间和帮助
这是我创建表格和图表的宏部分。
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
解决方案
这很可能是因为已使用/共享相同的缓存。您可以尝试以下方法:
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")
谢谢
推荐阅读
- javascript - 当 darn 变量未定义时,为什么 ejs 不允许 if else 语句?
- python - 每个用户将有一个子域 (username.domaine.com) + 添加自定义域 (ustomUserDomaine.com) 的可能性?
- android - 为什么在Android上按下后退按钮时会调用回车转换?
- javascript - Javascript(数据类型字符串的错误识别),匹配应该在引号内的单词
- javascript - 如何创建一个 Javascript 函数,它将在 HTML 中插入适当的图标?
- r - ggplot2:比例与坐标变换
- angular - 当我们在角度的子路由中时,如何获取直接父路由 URL?
- php - 如何使用 PHP 中的年、月、日等变量计算一个人的年龄
- random - 什么样的 PRNG 会匹配这样的散点图?
- constraints - 使用 OptaPlanner 创建具有一些棘手约束的学校时间表