【发布时间】:2018-02-21 03:33:50
【问题描述】:
所以我已经能够在某种程度上创建一个数据透视表,我会告诉你我的意思。到目前为止,这是我的代码。
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
Set WSD = Worksheets("aggregateData")
Set WSD2 = Worksheets("Sheet12")
' 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.Add(SourceType:=xlDatabase, SourceData:=PRange)
'Where do I want the pivot table to start
StartPT = WSD2.Range("A1").Address(ReferenceStyle:=xlR1C1)
'Begin to Create the Pivot Table
Set PT = PTCache.CreatePivotTable(TableDestination:=StartPT, TableName:="POS Data")
PT.PivotFields("Fineline").Orientation = xlRowField
End Sub
当我运行这段代码时,我得到了一个数据透视表的开头。但是,数据透视表显示为白色,而不是普通数据透视表的蓝色。任何帮助,将不胜感激。
谢谢,
G
【问题讨论】: