通过 VBA 更改枢轴源
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18708126/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change pivot source through VBA
提问by Sam
I get "Invalid procedure or call" when I use the code below in order to change the pivot source range in VBA. What is the right syntax for doing this? Thanks in advance.
当我使用下面的代码来更改 VBA 中的枢轴源范围时,我得到“无效的过程或调用”。这样做的正确语法是什么?提前致谢。
Dim DataArea As Variant
'...
DataArea = "Raw_Data!R1C1:R" & Selection.Rows.Count & "C" & Selection.Columns.Count
Sheets("Pivot-view").Select
Range("A1").Select
ActiveSheet.PivotTables("PivotTable1").ChangePivotCache ActiveWorkbook. _
PivotCaches.Create(SourceType:=xlDatabase, SourceData:=DataArea, _
Version:=xlPivotTableVersion14)
回答by Jaycal
If DataArea
is a valid, named rangein your workbook, then the reference to it in your macro needs to be in quotes; therefore, update
如果DataArea
是工作簿中有效的命名范围,则宏中对它的引用需要用引号引起来;因此,更新
SourceData:=DataArea,
SourceData:=DataArea,
to become
成为
SourceData:="DataArea",
SourceData:="DataArea",