PivotCache.Create unable to handle large Range

我是研究僧i 提交于 2019-12-29 01:57:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!