简体   繁体   English

如何使用VBA自动使用来自单独的excel工作簿的数据透视表的数据填充excel工作表?

[英]How would I use VBA to automatically populate an excel worksheet with data from the pivot table of a separate excel workbook?

I have two open Excel workbooks. 我有两个打开的Excel工作簿。 One has some data in a pivot table, like so: 一个在数据透视表中有一些数据,如下所示:

Row Labels   Date
A             5

B             4

C             3

The other, separate workbook is blank other than Column A, which lists the same Row Labels as are in the pivot table, but possibly in a different order: 除列A以外,另一个单独的工作簿为空白,其中列A与数据透视表中的行标签相同,但顺序可能不同:

Row Labels 行标签

B

A 一种

C C

I would like to place a button on the second workbook that, when pushed, will automatically populate the row labels with the appropriate columns from the pivot table, in the correct order. 我想在第二个工作簿上放置一个按钮,当按下该按钮时,它将以正确的顺序自动使用数据透视表中的相应列填充行标签。

I know that VLOOKUP will be involved somehow, but I am not quite sure how to get there. 我知道VLOOKUP会以某种方式参与其中,但是我不确定如何到达那里。 Ideally, it would be nice if this VBA code could be dynamic, so that the button would work no matter the size of the pivot table, and no matter how many row labels will be in the second workbook. 理想情况下,如果此VBA代码可以动态运行,那就太好了,这样无论透视表的大小如何,第二个工作簿中有多少行标签,该按钮都可以工作。

Use the GETPIVOTDATA function - for example: 使用GETPIVOTDATA函数-例如:

    =GETPIVOTDATA("Date",[PivotWorkbook]Sheet1!$A$1,"Row Field",$A2)

The workbook containing the Pivot Table must be open to calculate the result. 必须打开包含数据透视表的工作簿才能计算结果。

暂无
暂无

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

相关问题 当新数据加载到工作表中时,我将使用什么公式使列自动填充到 Excel 中? - What formula would I use to make a column automatically populate in excel when new data is loaded into a worksheet? 使用VBA宏将每个Excel工作表另存为单独的工作簿 - Use VBA Macro to Save each Excel Worksheet as Separate Workbook 如何使用Excel VBA从使用文件浏览器选择的工作簿中复制工作表? - How do I use Excel VBA to copy a worksheet from a workbook selected using a file browser? 如何使用工作簿和工作表的变量将数据从一个 Excel 工作簿复制到另一个 Excel 工作簿? - How can I copy data from one Excel workbook to another Excel workbook using variables for Workbook and Worksheet? Excel 2010 - 将数据透视表的数据源从外部更改为工作簿中的工作表 - Excel 2010 - Change data source of pivot table from external to worksheet within workbook 使用Excel VBA将.msg文件中的粘贴表数据复制到Excel工作表中的单独单元格中 - Copy Paste table data from a .msg file into separate cells in an Excel worksheet using Excel VBA 在与源数据相同的工作表中创建数据透视表 (Excel VBA) - Create pivot table in the same worksheet as the source data (Excel VBA) Excel VBA在另一个工作簿中使用数据透视表数据 - Excel VBA Using pivot table data in another workbook 从 excel 表填充工作表 - populate worksheet from excel table 使用VBA将另一个工作簿中的工作表加载到Excel中 - Loading a worksheet from another workbook into Excel with VBA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM