vba - 数据透视表创建中的过程调用或参数无效
问题描述
我很难找到这个错误的解决方案,我检查了很多帖子但无济于事,仍然是这条线有问题
Set ptable = pCache.CreatePivotTable( _
TableDestination:=DestSheet.Cells(1, 1), _
TableName:="PivotTable1", _
DefaultVersion:=6)
所以这是代码
Sub TestPivot()
Dim mySourceData As String
'Declare Variables
Dim SourceSheet As Worksheet
Dim DestSheet As Worksheet
'Declare Variales row and column
Dim FirstRow As Long
Dim LastRow As Long
Dim FirstCol As Long
Dim LastCol As Long
Dim ptable As PivotTable
Dim pCache As PivotCache
'Set/Define Source and Destination Variables
With ThisWorkbook
Set SourceSheet = Worksheets("W")
Set DestSheet = Worksheets("Pivot_W")
End With
'identify first row and first column of source data cell range
FirstRow = 2
FirstCol = 2
'Find last row and last column of source data cell range
'And obtain address of source data cell range
With Sheets("W").Range("A:N")
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
LastCol = Cells(1, Columns.Count).End(xlToLeft).Column
mySourceData = .Range(.Cells(FirstRow, FirstCol), .Cells(LastRow, LastCol)).Address(ReferenceStyle:=xlR1C1)
End With
'Insert Pivot Table
Set pCache = ThisWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=SourceSheet.Name & "!" & mySourceData, Version:=6)
Set ptable = pCache.CreatePivotTable(TableDestination:=DestSheet.Cells(1, 1), TableName:="PivotTable1", DefaultVersion:=6)
If Not IsEmpty(ptable) Then
MsgBox "non vide"
End If
With DestSheet.PivotTables("PivotTable1").PivotFields("Magasin")
.Orientation = xlRowField
.Position = 1
End With
End Sub
感谢您的帮助,并感谢您阅读我的帖子。
解决方案
推荐阅读
- java - 如何捕获亚马逊产品 selenium 的 xpath
- python - Django pyodbc 支持 Nexus DB 还是依赖于数据库?
- html - 我怎样才能使间距相等?
- sql - 我想在从 oracle 中选择时格式化电话号码列
- c# - 如何使用 LINQ 在字符串的一部分上创建组?
- machine-learning - ML.NET 预测客户订单数量
- python-3.x - Pytorch:相同输入的向量乘法结果不同
- flutter - 从颤动的共享首选项中读取字符串
- angular - 如果用户未登录,则阻止页面呈现
- javascript - 使用扩展减少 es6 缺少的对象嵌套数组