我有一个从3个字段创建的数据透视表,其中(例如):
field1值为:"1", "3", "5"
field2值为:"A", "B", "C"
field3值为:"X", "Y", "Z"
因此,给定一个数据透视表PT1,我想以与PT1["1"]["B"]["Y"]
类似的方式引用表中的单元格,并返回一个Range项。这可能吗?感谢。
编辑:代码:
Public Sub ColorIt2()
Dim rng As Range
For Each t_item In ActiveSheet.PivotTables("PivotTable1").PivotFields("F1").PivotItems
For Each r_item In ActiveSheet.PivotTables("PivotTable1").PivotFields("F2").PivotItems
For Each h_item In ActiveSheet.PivotTables("PivotTable1").PivotFields("F3").PivotItems
For Each b_item In ActiveSheet.PivotTables("PivotTable1").PivotFields("F4").PivotItems
If t_item.RecordCount <> 0 Or _
r_item.RecordCount <> 0 Or _
h_item.RecordCount <> 0 Or _
b_item.RecordCount <> 0 Then
Set rng = ActiveSheet.PivotTables("PivotTable1").GetPivotData(t_item, r_item, h_item, b_item)
rng.Select
Selection.Interior.ColorIndex = 40
Selection.Interior.Pattern = xlSolid
End If
End If
Next b_item
Next h_item
Next r_item
Next t_item
End Sub