设置数据透视缓存时类型不匹配 [英] Type mismatch when setting up pivotcache
本文介绍了设置数据透视缓存时类型不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将pCach用作PivotCache
I have pCach as PivotCache
我刚做的时候
ThisWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=pTRng).CreatePivotTable(TableDestination:= _
wOPT.Cells(3, 1), TableName:="PivotTable2")
它按预期方式工作,并在目标单元格上插入数据透视缓存
It works as expected and inserts pivotcache on the destination cell
但是当我尝试这样做时,会给我输入类型不匹配的错误吗?
But when I try this it gives me type mismatch error?
Set pCach = ThisWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=pTRng).CreatePivotTable(TableDestination:= _
wOPT.Cells(3, 1), TableName:="PivotTable2")
推荐答案
尝试将 PivotCache
和 PivotTable
设置为2条单独的代码行,如下面的代码所示:
Try splitting setting the PivotCache
and the PivotTable
to 2 seperate code lines, like in the code below :
Dim pTbl As PivotTable
Dim pCach As PivotCache
' set the Pivot Cache
Set pCach = ThisWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=pTRng)
' create a new Pivot Table in "wOPT" sheet, start from Cell A3
Set pTbl = wOPT.PivotTables.Add(PivotCache:=pCach, TableDestination:=wOPT.Range("A3"), TableName:="PivotTable2")
这篇关于设置数据透视缓存时类型不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文