+ Reply to Thread
Results 1 to 23 of 23

Expand & Collapse Pivot Tables in multiple worksheets

  1. #1
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Expand & Collapse Pivot Tables in multiple worksheets

    Hi,

    I have 5 worksheets, 1, 2, 3 4 & 5
    all have identical Pivot Table columns A, B, C, D & E

    is there a way, using VBA, to expand or collapse the same column, say C, in all 5 worksheets at the same time instead of going into each one manually?

    Thanks

  2. #2
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Expand & Collapse Pivot Tables in multiple worksheets

    Hi Kaseyleigh,

    What do you mean by expand or collapse the column.. ?
    Is it the double click on the right border to auto - adjust or what?


    Regards,
    DILIPandey

    <click on below 'star' if this helps>
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), [email protected]

  3. #3
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Expand & Collapse Pivot Tables in multiple worksheets

    Hi,

    In Excel 2010, Pivot Tables now come with Expand / Collapse buttons.

    HTH

    Thanks

  4. #4
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Expand & Collapse Pivot Tables in multiple worksheets

    You want the showdetail property of the pivot field - for example
    Please Login or Register  to view this content.
    Good luck.

  5. #5
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Expand & Collapse Pivot Tables in multiple worksheets

    Hi Rory,

    Is there a way to use an event so when a use expands a Pivot Table on Sht 1, Col C Row 3, that exact same location in Shts 2, 3, 4 & 5 will also be expanded at the same time. OR collapse depending on what the User did.

    I hope I am making sense.

    Thanks

  6. #6
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Expand & Collapse Pivot Tables in multiple worksheets

    Unfortunately, the events are not that specific - all you will get is notification that the pivot table has changed, not what or why. You would therefore have to iterate through all the PTs and all the fields and reset the detail level, which is not terribly efficient. I also seem to recall having issues with reading the current ShowDetail value but that might be my memory playing tricks, as I haven't tried it for a while.

  7. #7
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Expand & Collapse Pivot Tables in multiple worksheets

    Oh no!

    Is a way to use ActiveCell and perform the same tasks in the subsequent shts?

    Thanks

  8. #8
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Expand & Collapse Pivot Tables in multiple worksheets

    Let's try it!

    This goes in the ThisWorkbook module of your workbook:

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Expand & Collapse Pivot Tables in multiple worksheets

    Hey Rory,

    That's it! You're a Genius!

    Thank you! Thank you!

    Please may I ask you to tell me what each line of your code does, so I can understand it?


    Thank you once again for your assistance.

  10. #10
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Expand & Collapse Pivot Tables in multiple worksheets

    Here is a commented version - hopefully it is clear
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Expand & Collapse Pivot Tables in multiple worksheets

    Thank you for going to all the trouble.

    I wouldn't have known where to begin.

    TY !

  12. #12
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Expand & Collapse Pivot Tables in multiple worksheets

    My pleasure.

  13. #13
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Expand & Collapse Pivot Tables in multiple worksheets

    Hi Rory,

    I need your assistance once again, to add something to your code, because I am getting a "Type mismatch" error when I refresh a Pivot Table

    Something like, if pt.RefreshTable exit sub. My novice attempt

    Thank you!

  14. #14
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Expand & Collapse Pivot Tables in multiple worksheets

    Any chance you can post the workbook?

    There aren't many lines there that aren't in an On Error Resume Next block so I'm struggling to see where that error might occur, but worst case you could try removing the two
    Please Login or Register  to view this content.
    lines

  15. #15
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Expand & Collapse Pivot Tables in multiple worksheets

    Taking a look at your code, my thoughts are >>
    Your code is looking for a ptField and if it's not "On Error GoTo ....". There will always be a ptField but the action I am performing is a Refresh not Expand / Collapse. Should the "On Error GoTo ...." be looking at something else? Am I heading in the wrong direction?

    The workbook is massive, I will put together a smaller version and post tomorrow.

  16. #16
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Expand & Collapse Pivot Tables in multiple worksheets

    Where is the activecell when you run the refresh? (ie which part of the pivot table?)

  17. #17
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Expand & Collapse Pivot Tables in multiple worksheets

    Anywhere in the Pivot Table.

    Mmm!

    Ignore me Rory, I have just tried Refresh again and it worked, no "Type Mismatch" error.

    Thanks

  18. #18
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Expand & Collapse Pivot Tables in multiple worksheets

    pt file.xlsm

    Hi Rory,

    I get that "Type mismatch" error intermittently :o/

    Please see attched, I hope you will be able to solve this

    Much appreciated!

  19. #19
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Expand & Collapse Pivot Tables in multiple worksheets

    Try this version
    Please Login or Register  to view this content.

  20. #20
    Forum Contributor
    Join Date
    10-29-2009
    Location
    London
    MS-Off Ver
    Excel 2013
    Posts
    125

    Re: Expand & Collapse Pivot Tables in multiple worksheets

    YES!

    Thanks Rory, I think that's it!

    Thank you !

  21. #21
    Registered User
    Join Date
    05-19-2011
    Location
    Delhi, India
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Expand & Collapse Pivot Tables in multiple worksheets

    I've created a Pivot in excel 2010, and it has expand collapse buttons (+ and -, screenshot attached). Now if someone opens this pivot in excel 2003, the '+' and '-" sign completely disappears. Is it possible to keep the expand collapse buttons intact in excel 2003 by doing some coding or by any option available within excel..
    I've hidden the contents of cells for the obvious reasons.
    thread.JPG

  22. #22
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Expand & Collapse Pivot Tables in multiple worksheets

    Hi ritesh25aug,

    Suggest you to not to post another question in other's question rather create a new thread.. look in forum rules:-

    http://www.excelforum.com/forum-rule...rum-rules.html

    Regards,
    DILIPandey

    <click on below 'star' if this helps>

  23. #23
    Registered User
    Join Date
    12-12-2012
    Location
    Boston
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Expand & Collapse Pivot Tables in multiple worksheets

    Hi Rory,

    I have multiple pivots in a single worksheet. the data source is an OLAP cube. I cannot make this macro run on that excel. Can you please help me with that.

    Thanks in Advance

    A.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1