?
Solved

How can I get pivot childfield value from Excel VBA

Posted on 2014-12-12
2
Medium Priority
?
215 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 52

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
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 Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

718 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