简体   繁体   English

Excel 2013使用VBA创建数据透视表

[英]Excel 2013 Creating a pivot table with vba

I have a macro that creates a pivot table. 我有一个创建数据透视表的宏。 It has worked great for year but not users are moving to Excel 2013 and it is not working. 一年来一直运行良好,但并非用户正在迁移到Excel 2013,并且它无法正常工作。 The one twist is that the range of data can change from user to user or time to time depending on a query they run. 一种扭曲是,数据范围可以根据用户运行的查询而在不同用户之间或不时更改。 I tried to modify the code to create the pivot table but I'm getting a syntax error. 我试图修改代码以创建数据透视表,但出现语法错误。

Recorded Code: 记录的代码:

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Results!R2C1:R633C25", Version:=xlPivotTableVersion15).CreatePivotTable _
TableDestination:="Sheet1!R3C1", TableName:="PivotTable1", DefaultVersion _
:=xlPivotTableVersion15

Modified Code using variable to determine the last row and column: 修改后的代码使用变量来确定最后一行和最后一列:

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Results!R2C1:R" & MyRow & "C" & MyCol, _ Version:=xlPivotTableVersion15.CreatePivotTable _
TableDestination:="Sheet1!R3C1", TableName:="PivotTable1", DefaultVersion _
:=xlPivotTableVersion15

Any suggestions on what is wrong with the modified code would be greatly appreciated. 修改后的代码有什么问题的任何建议,将不胜感激。 Thanks for your help 谢谢你的帮助

No longer an issue. 不再是问题。 The user got a new copy of the macro and it started working again. 用户获得了宏的新副本,并且它再次开始工作。 thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM