我已经使用以下代码生成了数据透视表。
Sub TCD()
Dim last_row As Integer
last_row = Cells(Rows.Count, 1).End(xlUp).Row
Dim My_range As Range
Set My_range = Range(Cells(1, 1), Cells(last_row, 2))
Dim sht As Worksheet
Dim pvtCache As PivotCache
Dim pvt As PivotTable
Dim StartPvt As String
Dim pf_Name As String
'Create a new worksheet
Set sht = Sheets.Add
sht.Name = "TCD"
'Where do you want Pivot Table to start?
StartPvt = "TCD" & "!" & sht.Range("A1").Address(ReferenceStyle:=xlR1C1)
'Create Pivot Cache from Source Data
Set pvtCache = ActiveWorkbook.PivotCaches.Create( _
SourceType:=xlDatabase, _
SourceData:=My_range)
'Create Pivot table from Pivot Cache
Set pvt = pvtCache.CreatePivotTable( _
TableDestination:=StartPvt, _
TableName:="PivotTable1")
pvt.PivotFields("Type_c").Orientation = xlRowField
pf_Name = "Max iteration par type"
pvt.AddDataField pvt.PivotFields("Nb_Iteration"), pf_Name, xlMax
'不执行任何操作的代码部分
Dim dbl As Double
dbl = pvt.GetData(Name:="CP")
End Sub
数据透视表看起来像这样
如何获取每个行元素的编号?我尝试使用get数据(最后两行代码)和getpivotdata。似乎没有任何作用。
以下内容如何?
dbl = pvt.GetData("'Max iteration par type' CP")