1

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

2
  • 1
    Try using a range address rather than a Range object for the SourceData argument.
    – Rory
    Sep 16, 2014 at 13:50
  • It worked. But i hardcoded the range now. I need to input dynamically the range based on the input?
    – kayle
    Sep 16, 2014 at 13:55

1 Answer 1

3

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
1
  • It helped me, too, after days spent trying to figure it out! Feb 18, 2016 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.