Solved

How can I get pivot childfield value from Excel VBA

Posted on 2014-12-12
2
185 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 50

Accepted Solution

by:
Rgonzo1971 earned 500 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

756 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