Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
vba excel通过缓存或新建创建透视表_Vba_Excel_Excel 2010 - Fatal编程技术网

vba excel通过缓存或新建创建透视表

vba excel通过缓存或新建创建透视表,vba,excel,excel-2010,Vba,Excel,Excel 2010,在vba excel宏工具上,我需要从两个数据表创建许多新的工作表和透视表 我们有两条路 使用数据透视缓存创建新的数据透视表 反复使用相同的数据表创建新的透视表 如果我选择第二种方法会有什么影响 这会使我们的excel文件更重吗 是否要跳过第一种方法,因为如果需要依赖关系,每个excel工作簿中都应该有第一个透视表 使用excel 2010。我做了一个项目,它将在现有表格中创建数据透视表,并将数据复制到新的电子表格中。如果这是你的问题,请参考下面的代码 Dim objtable as pivot

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

我们有两条路

  • 使用数据透视缓存创建新的数据透视表
  • 反复使用相同的数据表创建新的透视表
  • 如果我选择第二种方法会有什么影响

    这会使我们的excel文件更重吗

    是否要跳过第一种方法,因为如果需要依赖关系,每个excel工作簿中都应该有第一个透视表


    使用excel 2010。

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

    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 '
    

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