views:

18

answers:

1

Hi, I have a pivot table created from 3 fields where (for example):

field1 values are: "1", "3", "5"
field2 values are: "A", "B", "C"
field3 values are: "X", "Y", "Z"

So given a pivot table PT1 I want to reference a cell within the table in a similar way to PT1["1"]["B"]["Y"] and get a Range item returned. Is this possible? Thanks.

EDIT: codes:

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
A: 

Not sure, but maybe you want the GetPivotData function?

GSerg
Or maybe this one http://msdn.microsoft.com/en-us/library/aa195746(office.11).aspx using VBA. I'm getting an undefined error :S
mathon12
@mathon12: How do you call it? Edit you question to include some code please.
GSerg
Okay, added. It seems odd to me that it has two completely different interfaces.
mathon12