我有一个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
- 2. VBA Excel数据透视表
- 3. 数据透视表与VBA
- 4. 在VBA中创建数据透视表
- 5. 在VBA中复制数据透视表
- 6. 从数据库检索VBA
- 7. 从数据透视表提取数据vba
- 8. 创建数据透视表的Excel VBA
- 9. 从VBA中的数据透视表字段列表中删除数据透视表字段
- 10. 根据索引数据透视表中的值选择数据
- 11. 隐藏数据透视表中的数据透视表项
- 12. 从列表视图中检索数据
- 13. 从数据透视表
- 14. 从数据透视表中提取数据到数据框(即“反向透视”)
- 15. VBA数据透视表彼此之间
- 16. VBA选择数据透视表
- 17. 使用VBA刷新数据透视表
- 18. VBA数据透视表过滤器
- 19. vba创建数据透视表excel 2015
- 20. VBA块数据透视表创建
- 21. VBA无法显示数据透视表
- 22. VBA,数据透视表向导方法
- 23. VBA:创建数据透视表
- 24. 数据透视表展开“值”VBA
- 25. 使用VBA隐藏数据透视表
- 26. Excel VBA从表中创建数据透视表
- 27. 复制的数据透视表上的VBA数据丢失
- 28. 从SQLite数据库的列表视图中检索数据
- 29. Laravel从数据透视表检索状态
- 30. 如何从Excel 2007数据透视表检索sql代码
任何帮助,请?????? – 1355 2011-02-28 11:55:45