【发布时间】:2019-07-11 15:21:04
【问题描述】:
例如,当我单击数据透视表中的单元格G14 时。它应该在另一张表中显示9 data,比如Sheet1。数据的数量取决于数据透视表的column G 中的单元格。我似乎找不到任何代码来获取该数据。
我需要知道如何使用 VBA 访问这些数据。
【问题讨论】:
-
什么是“9数据”?
标签: excel vba pivot-table
例如,当我单击数据透视表中的单元格G14 时。它应该在另一张表中显示9 data,比如Sheet1。数据的数量取决于数据透视表的column G 中的单元格。我似乎找不到任何代码来获取该数据。
我需要知道如何使用 VBA 访问这些数据。
【问题讨论】:
标签: excel vba pivot-table
Sub SelectAndCopyPaste()
Dim lastrow() As String
Dim pt As PivotTable
Worksheets("Sheet1").Activate
ActiveSheet.Cells.Clear
With Worksheets("Pivot Sheet")
.Activate
Set pt = .PivotTables("PivotTable2")
lastrow = Split(pt.RowRange.Address, ":")
.Range(lastrow(1)).Offset(-1, 6).Select 'here is where you set which cell you want to choose
Selection.ShowDetail = True
Selection.Copy
End With
Worksheets("Sheet1").Select
ActiveSheet.Cells(1, 1).PasteSpecial xlPasteValues
End Sub
【讨论】: