尝试使用数据从“过滤列表”标签到“数据透视表”标签创建数据透视表。
获取行的类型不匹配错误
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=rngData, Version:=xlPivotTableVersion12).CreatePivotTable TableDestination:=wsPvtTbl.Range("A1"), TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion12
Set PvtTbl = wsPvtTbl.PivotTables("PivotTable1")
代码是
LastRow21 = wkb2.Worksheets("FilteredList").Cells(Rows.Count, 1).End(xlUp).Row
LastCol21 = wkb2.Worksheets("FilteredList").Cells(1, Columns.Count).End(xlToLeft).Column
Set rngData = wkb2.Worksheets("FilteredList").Cells(1, 1).Resize(LastRow21, LastCol21)
Set wsPvtTbl = wkb2.Worksheets("Pivots")
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=rngData, Version:=xlPivotTableVersion12).CreatePivotTable TableDestination:=wsPvtTbl.Range("A1"), TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion12
Set PvtTbl = wsPvtTbl.PivotTables("PivotTable1")