Home » excel » Type mismatch during creation of pivot table : Excel vba

Type mismatch during creation of pivot table : Excel vba

Posted by: admin May 14, 2020 Leave a comment

Questions:

I new to VBA. I am trying to create pivot table for very big record(around 30K Record). This is my code for creating the pivot table. while creating the pivot table it throws error as “Type mismatch”. It was working fine for small set of records.

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=rngData, _
Version:=xlPivotTableVersion12).CreatePivotTable TableDestination:=wsPvtTbl.Range("A1"), _
TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion12

Please help me on this.
Thanks in advance

How to&Answers:

You can use something like this with your rngData variable:

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="'" & rngData.Worksheet.name & "'!" & rngData.Address(referencestyle:=xlR1C1), _
Version:=xlPivotTableVersion12).CreatePivotTable TableDestination:=wsPvtTbl.Range("A1"), _
TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion12