【问题标题】:vba excel create pivot table by cache or newvba excel通过缓存或新创建数据透视表
【发布时间】:2013-04-04 12:33:10
【问题描述】:

在 vba excel 宏工具上,我需要从两个数据表中创建许多新表和数据透视表。

我们有两种方式

  1. 使用数据透视缓存创建新的数据透视表。
  2. 使用相同的数据表一次又一次地创建新的数据透视表。

如果我选择第二种方法会有什么影响,

这会使我们的 excel 文件变重吗?

想要跳过第一种方法,因为如果需要依赖,则每个 excel 工作簿中都应该存在第一个数据透视表?

使用 excel 2010。

【问题讨论】:

  • 我认为第三次尝试是你的混合体......无论如何你都需要在某个地方“拥有”PivotCache。我在类似情况下所做的是创建一个引用 Range 的数据透视缓存,然后使用该 PivotChache 创建很多数据透视表,它工作得非常好......这是你的任何方式吗?
  • 这个宏需要在许多不同的文件上运行,必须有两个数据表,数据和数据范围会有所不同。使用数据透视缓存更容易,但为此我们必须确保它必须存在于 excel 文件中。
  • 我无法控制每个 excel 文件。
  • 如果我以编程方式创建一次,我是否能够重用它。我怎样才能识别它。它有名字吗?
  • 因此,如果您确定有一个数据透视表,您是对的,我会使用该 PT 缓存作为 PT 自行保留指向数据的链接。这似乎是一个不错且可靠的选择。但是,我对这种方式的效率没有经验。

标签: vba excel excel-2010


【解决方案1】:

我做了一个项目,它将在现有工作表中创建数据透视表并将数据复制到新的电子表格。如果这是你的问题..请参考下面的代码

Dim objtable as pivottable, objfield as pivotfield
set objtable = sheet1.pivotwizard
   ptname = activesheet.pivottables(1).name 'this code is to give pivot table name which will help in creating new pivot tables
   set objfield.objtable.pivotfields("Month") 'this code will select month in page field
 objfield.orientation = xlpagefield
set objfield = objtable.pivotfields ("Dept & Mgr") 'this code will select dept & mgr in page field
objfield.orientation = xlpagefield
set objfield = objtable.pivotfields("Legal Entity") 'this code will select legal entity in row field
objfield.orientation = xlrowfield
set objfield = objtable.pivotfields("Cost Code") 'this code will select cost code in row field
objfield.orientation = xlrowfield
set objfield = objtable.pivotfields("CC Description") 'this code will select CC Description in row field
objfield.orientation = xlrowfield
set objfield = objtable.pivotfields("User") 'this code will select Usr in row field
objfield.orientation = xlrowfield
set objfield = objtable.pivotfields("Carrier") 'this code will select carrier in row field
objfield.orientation = xlrowfield
set objfield = objtable.pivotfields("Description") 'this code will select Description in row field
objfield.orientation = xlrowfield
set objfield = objtable.pivotfields("Amount Incl Tax") 'this code will amount incl tax in Datafield
objfield.orientation = xlDatafield
activesheet.pivottables(ptname).format xlreport6 '

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多