我遇到了数据透视表的问题。出于某种原因,这段代码今天早上工作,但现在不是。这是我的代码,直到错误。VBA代码使数据透视表不能正常工作
Dim WSD2 As Worksheet
Set WSD2 = ActiveWorkbook.Sheets.Add(After:= _
Worksheets(Worksheets.Count))
WSD2.Name = "POS Info"
'--------------------------------------------------
' Step 2: Create the pivot table
'--------------------------------------------------
Dim WSD As Worksheet
Dim PTCache As PivotCache
Dim PT As PivotTable
Dim PRange As Range
Dim FinalRow As Long
Dim FinalCol As Long
Dim StartPT As String
Dim BottomRowStart As Range ' this is for pivot table
Dim BottomRowEnd As Range ' this is for pivot table
Set WSD = Worksheets("aggregateData")
' Select the data for pivot table
FinalRow = WSD.Cells(Rows.Count, 2).End(xlUp).Row
FinalCol = WSD.Cells(1, Columns.Count).End(xlToLeft).Column
Set PRange = WSD.Cells(2, 1).Resize(FinalRow, FinalCol)
Set PTCache = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=PRange, Version:=xlPivotTableVersion14)
'Where do I want the pivot table to start
StartPT = WSD2.Range("A1").Address(ReferenceStyle:=xlR1C1)
Set WSD2 = Worksheets("POS Info")
'Begin to Create the Pivot Table
Set PT = PTCache.CreatePivotTable(TableDestination:=StartPT, TableName:="POS Data")
最后一行是从哪里获得以下错误消息:
“应用程序定义或对象定义的错误”。
任何帮助将不胜感激。
谢谢,
ģ
据我所知,'TableDestination'必须是'Range',而不是地址。 – GSerg