简体   繁体   English

没有在不同的工作表上创建具有不同缓存的第二个数据透视表

[英]Second Pivot Table with different Cache, on different Sheet, isn't being created

I am clearly missing something obvious.我显然错过了一些明显的东西。

I create a Pivot Table based on one sheet, and get all the data fields.我基于一张工作表创建一个数据透视表,并获取所有数据字段。 Then, when I try to create a new Cache from a second source sheet, the new Pivot Table does not appear.然后,当我尝试从第二个源表创建新的缓存时,新的数据透视表不会出现。

lRow = Sheets("Source1").Cells(Sheets("Source1").Rows.Count, 1).End(xlUp).Row
lCol = Sheets("Source1").Cells(1, Sheets("Source1").Columns.Count).End(xlToLeft).Column

' Manipulate data, including new columns
Set PRange = Sheets("Source1").Cells(1, 1).Resize(lRow, lCol + 2)
Set PDest = Sheets("Source1 Summary")

Set PCache = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    PRange).CreatePivotTable(TableDestination:= _
    PDest.Cells(3, 1), TableName:="Source1Pivot")

' Set up the table with the data fields, all works perfectly

'For the new Pivot Table:
lRow = Sheets("Source2").Cells(Sheets("Source2").Rows.Count, 1).End(xlUp).Row
lCol = Sheets("Source2").Cells(1, Sheets("Source2").Columns.Count).End(xlToLeft).Column

Set PRange = Sheets("Source2").Cells(1, 1).Resize(lRow, lCol + 1)
Set PDest = Sheets("Source2 Summary")

Set PCache2 = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    PRange).CreatePivotTable(TableDestination:= _
    PDest.Cells(3, 1), TableName:="Source2Pivot")

At this point, no new Pivot Table is created, and adding fields does not work.此时,没有创建新的数据透视表,添加字段不起作用。 The macro ends with "Source2 Summary" being blank.宏以“Source2 Summary”为空结束。

I did verify that the new lRow and lCol were pulling from the Source2 page.我确实验证了新的 lRow 和 lCol 是从 Source2 页面中提取的。 Can you see something silly that I've missed?你能看到我错过的一些愚蠢的东西吗? I haven't been able to find any information about setting up a new pivot with new source on a new page... presumably because it usually just works!我一直无法找到有关在新页面上使用新源设置新数据透视表的任何信息……大概是因为它通常可以正常工作!

您将 prange 设置为比基础数据宽两列,因此无法创建数据透视表,因为这些空白列没有列标题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM