问题
This run ok:
Dim pc As PivotCache
With tgtBook.Sheets("Data")
Set pc = tgtBook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=Range("A1:B5"), Version:=Excel.xlPivotTableVersion14) ' Range("myMthdata"))
End With
The throws a Run-time error '13' Type mismatch:
Dim pc As PivotCache
With tgtBook.Sheets("Data")
Set pc = tgtBook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=Range("A1:B500000"), Version:=Excel.xlPivotTableVersion14) ' Range("myMthdata"))
End With
The only difference is the number of rows in the SourceData. Is this a bug or is there a logical reason behind this seeming inconsistency?
EDIT
On further investigation it seems like B65536 will work whereas anything greater will bug. This is the max number of rows in the old version of Excel not excel-2010
. Feels like a bug.
Anybody know a workaround?
回答1:
In my experience, it works better if you use an R1C1 style reference rather than a Range object or an A1 style string:
Dim pc As PivotCache
Set pc = tgtBook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="Data!R1C1:R500000C2", Version:=Excel.xlPivotTableVersion14)
来源:https://stackoverflow.com/questions/25606962/pivotcache-create-unable-to-handle-large-range