【发布时间】:2017-12-08 09:00:32
【问题描述】:
我在数据透视报告过滤器中有国家代码。我想获取可见的枢轴项数据并将每个值放在 A1 的每个单元格中。我使用了下面的代码。但所有单元格仅显示过滤器中的最后一个值。我需要从 A1 自动移动。帮帮我
Sub Getpivotitem()
Dim ws As Worksheet
Dim str1 As Variant
Dim Data As Variant
Dim rng As Range
Set rng = Range("A1:X1")
Set ws = Sheets("Sheet1")
Dim pi As PivotItem
For Each pi In ws.PivotTables("PivotTable1").PivotFields("Country Code").PivotItems
If pi.Visible = True Then
For Each cell In rng.Columns
cell.Value = pi
Next cell
End If
Next pi
End Sub
【问题讨论】:
-
您的数据透视表数据与您的预期结果不同。
FR、DE、ES.... 在您的数据透视表中的什么位置? -
@harun24hr 是的,我在数据透视表的值中选择了这些值。
标签: vba excel excel-2010 pivot-table