Consulting

Results 1 to 11 of 11

Thread: Solved: Big Automation Question with Pivot Tables and Graphs

  1. #1

    Solved: Big Automation Question with Pivot Tables and Graphs

    Hi folks,

    Ok my terminology may be wrong here, so I'm going to try and be as specific as I can.

    I have a large pivot table, and a graph that changes based upon what is chosen within the pivot. What i'm trying to do is find a way to make the graph titles change as well. In order to do this, I'd like to obtain the list of chosen filters within one pivot field. Is there a way, either through vba or some formula, to place this list somewhere on my sheet outside of the pivot table? Then I can add the chosen filter names to my concatenate formula. If you think you may be able to help me but this question isn't clear, please don't hesitate to ask me to re-word whatever doesn't make sense. I will be here at my desk for at least the next hour, and all day on Monday.

    Thank you!

    Edit: I have attached a picture for help. Based upon this, I'd like Beverly, Essex, Lowell and Malden to be listed somewhere outside of my pivot table.

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,057
    Location
    Can you post a sample workbook?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    Here is an example of what I'm trying to do. I know I could just automatically create a pivot chart, but my "user audience" also wants to breakout chart on the left (and it's preferable to have everything on one sheet tab.) In addition, the chart bars end up being an overall reflection of multiple questions (where in my vbaexpress example each question is represented individually.) What i'm trying to do is obtain the dynamic list of chosen options within the town and company dropdowns in the pivot table, which will be the criteria for naming my graph.

    Does this help?

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Put this in a standard module
    [VBA]
    Function Towns(data As Range)
    Dim cel As Range, t As String
    For Each cel In data
    If cel <> "" Then t = t & cel & ", "
    Next
    Towns = Left(t, Len(t) - 1)
    End Function

    [/VBA]

    and in say Z4
    =towns(Z16:Z100)

    Is that what you are after?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    This is great Md, and 99% of what I was looking for. While running the module, it listed all of the Towns in one cell. Is it possible to list the second town in the cell below the first one, and so on?

    Either way, thanks for your help.

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Run this to list towns in the activecell and below

    [vba]Sub Towns()
    Dim cel As Range, t As String
    For Each cel In Range("Z16:Z100")
    If cel <> "" Then
    ActiveCell.Offset(i) = cel
    i = i + 1
    End If
    Next
    End Sub[/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    this is perfect, thanks a ton.

  8. #8
    Actually, one last question..... after reading your update, I assumed it worked. I'm sure it still does, but I just don't know where to put it. Does this replace the original code, or is it in addition to it? If I just add it below the original module code, and then call it (in Z4 as you suggested), I get an error saying that the name isn't valid.

  9. #9
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    This replaces the original code. The first works as a Function and returns a value. The second writes values into the cells.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  10. #10
    Ok i'm sure I'm overlooking something very easy here. Is that code placed in a module, just as the original? Or is it placed in the sheet code? Then, assuming I want it to run beginning in cell Z4 (as the original example suggested) do I just type =Towns(Z16:100) ? Right now the code is in module1, and I was typing =Towns(Z16:Z100) in cell Z4.... I'm getting a "That name is not valid" error.

    Apologies for the inexperience. And thank you for helping.




    Edit: Ah, I see. It needs to be "run(Towns)" in the Intermediate window of VBA. I'm looking for this portion of my file to update automatically upon pivot table change, so I think I'll have to use your first version of the code and find a way to make it work. Thanks for the help MD, I appreciate it.
    Last edited by Eric58132; 04-27-2009 at 01:17 PM.

  11. #11
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Try this version
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •