简体   繁体   English

VBA EXCEL 创建一个包含所有填充单元格的数据透视表

[英]VBA EXCEL Create a pivot table with all populated cells

I'm trying to create in FILTERED worksheet a pivot table from all non-empty cells in ALL_RECORDS worksheet,(populated cells will be different every day), as follows :我试图在 FILTERED 工作表中从 ALL_RECORDS 工作表中的所有非空单元格创建一个数据透视表,(填充的单元格每天都会不同),如下所示:

    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "ALL_RECORDS!R1C1:R3992C19", Version:=6).CreatePivotTable _
        TableDestination:="FILTERED!R3C1", TableName:="TablaDinámica1", _
        DefaultVersion:=6
    Sheets("FILTERED").Select
    Cells(3, 1).Select

But I keep getting error 5 (Invalid procedure call or argument) Even if i do it by saving a macro... I need to create the pivot table each time the macro runs.但是我不断收到错误 5(无效的过程调用或参数)即使我通过保存宏来做到这一点......每次宏运行时我都需要创建数据透视表。 Any help will be greatly appreciated.任何帮助将不胜感激。 Thanks in advance!提前致谢!

I tried to reproduce your error code, and the only case i have this error is when the sheet "FILTERED" doesn't exist.我试图重现您的错误代码,我遇到此错误的唯一情况是工作表“已过滤”不存在。 You have to create it before launching the creation of pivot table.您必须在开始创建数据透视表之前创建它。

Example :例子 :

Sheets.Add After:=ActiveSheet
ActiveSheet.Name = "FILTERED"
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    "ALL_RECORDS!R1C1:R3992C19", Version:=6).CreatePivotTable _
    TableDestination:="FILTERED!R3C1", TableName:="TablaDinámica1", _
    DefaultVersion:=6
Sheets("FILTERED").Select
Cells(3, 1).Select

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

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