Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How can I get pivot childfield value from Excel VBA

Posted on 2014-12-12
2
Medium Priority
?
236 Views
Last Modified: 2014-12-14
In the attached file I have some data and a Pivot table.
In the data source column #3 (Sub Project Number) is a value that I do not show, but a value I need.

When selecting a subproject in the Pivot, how do I get the value of the Sub Project NUmber child item using Excel VBA.

Please notice that the column "Sub Project" is not Unique. (10 - XXXXX)

Thank you
C--Users-hhbr-Desktop-Pivot-Example.xlsx
0
Comment
Question by:Hans Henrik Brandt
2 Comments
 
LVL 53

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 40496187
Hi,

pls try

Sub Macro()

Set Sel = Selection

On Error Resume Next
Set pvtfld = Sel.PivotField
On Error GoTo 0

If Not IsEmpty(pvtfld) Then
    If Sel.PivotField.Name = "Sub Project" Then
    SubProjectName = Sel.Formula
    Idx = 0
    Do
        Idx = Idx - 1
    Loop Until Sel.Offset(Idx).PivotField.Name <> "Sub Project"
    MainProjectName = Sel.Offset(Idx).Formula
    Result = Evaluate("=INDEX(Table1[Sub Project Number],MATCH( " & Chr(34) & MainProjectName & SubProjectName & Chr(34) & ",Table1[Main Project]&Table1[Sub Project],0))")
    MsgBox "Result: " & Result
    End If
End If

End Sub

Open in new window

Regards
0
 

Author Comment

by:Hans Henrik Brandt
ID: 40499548
Thank you so much :). Did the job perfectly.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question