Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Excel VB.net Add-in Find Pivot header based on pivot cell

Hi

In the following pivot what VBA code would I use to find the header (eg Goal, Status, Task) based on the cell I am in. The pivot can change so I need to be able to do this dynamically.

I use the following code to get the pivot cell to the left:

    Function Get_Pivot_Cell_to_Left() As String
        Try
            'Gets the pivot cell value to left even where label is blank
            Dim pCell As Excel.PivotCell
            'pCell = Globals.ThisAddIn.Application.ActiveCell.PivotCell
            pCell = Globals.ThisAddIn.Application.ActiveCell.PivotCell
            If pCell.PivotField.Position > 1 Then
                Get_Pivot_Cell_to_Left = pCell.PivotRowLine.PivotLineCells(pCell.PivotField.Position - 1).PivotItem.Caption
            End If

        Catch ex As Exception
            MsgBox("Problem getting Task data " & ex.Message)
            Get_Pivot_Cell_to_Left = ""
        End Try
    End Function

User generated image
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Does this code return you header of the left side?
ASKER CERTIFIED SOLUTION
Avatar of Murray Brown
Murray Brown
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Murray Brown

ASKER

this post answered the original question