我有一个Excel工作表,其中包含三个数据透视表名称为PivotTable1 ... PivotTable3和活动字段名称分别为国家,语言和打印机的三个数据透视表。我需要的是将每个数据透视表中的所有数据都存储到每个字符串或字符串数组中。任何帮助将非常感谢。从Vba中的数据透视表检索数据
2
A
回答
2
快速&肮脏的一个让你走;一个线性字符串中的数据透视表的所有单元格,由“;”分隔。这应该给予使用哪些方法和属性足够的启发。注意:Tmp
不能保留无限大的数据透视表,如果它们变得非常大,请考虑将Tmp
写入文件。
Sub PTTest()
Dim SH As Worksheet ' the current worksheet from the colection of workbooks
Dim PT As PivotTable ' the current pivot table from the current worksheet
Dim PTC As Range ' the cell range of the current pivot table
Dim Tmp As String ' the buffer for concatenated cell values
Tmp = ""
' process all sheets, as Pivot table objects are contained by sheets
For Each SH In ActiveWorkbook.Worksheets
For Each PT In SH.PivotTables
For Each PTC In PT.TableRange1.Cells
' all cells in one buffer, seperated by ";"
' if you want to include page header cells, use
' "PT.TableRange2.Cells" instead
Tmp = Tmp & PTC & ";"
Next PTC
' *** do something *** with the buffer
' ok very simple we print it into the debugger's Immediate window
Debug.Print Tmp
' empty buffer for next pivot table
Tmp = ""
Next PT
Next SH
End Sub
希望帮助....好运气拾音
相关问题
- 1. VBA Excel数据透视表
- 2. 数据透视表与VBA
- 3. 在VBA中创建数据透视表
- 4. 在VBA中复制数据透视表
- 5. 从数据库检索VBA
- 6. 从数据透视表提取数据vba
- 7. 创建数据透视表的Excel VBA
- 8. 从VBA中的数据透视表字段列表中删除数据透视表字段
- 9. 隐藏数据透视表中的数据透视表项
- 10. 根据索引数据透视表中的值选择数据
- 11. 从列表视图中检索数据
- 12. VBA块数据透视表创建
- 13. VBA数据透视表过滤器
- 14. VBA数据透视表彼此之间
- 15. 数据透视表展开“值”VBA
- 16. VBA无法显示数据透视表
- 17. 使用VBA填充数据透视表
- 18. VBA,数据透视表向导方法
- 19. VBA:创建数据透视表
- 20. vba创建数据透视表excel 2015
- 21. 使用VBA隐藏数据透视表
- 22. Excel VBA从表中创建数据透视表
- 23. 复制的数据透视表上的VBA数据丢失
- 24. 从SQLite数据库的列表视图中检索数据
- 25. 如何从Excel 2007数据透视表检索sql代码
- 26. Laravel从数据透视表检索状态
- 27. 使用VBA更改数据透视表数据源的错误
- 28. 在VBA的数据透视表模板上定义源数据
- 29. Laravel的数据透视表+一般的数据透视表
- 30. Excel的VBA来过滤数据透视表和数据透视表的前一天 - 透视过滤器字段
任何帮助,请?????? – 1355 2011-02-28 11:55:45