+ Reply to Thread
Results 1 to 18 of 18

Macro that willl affect all Pivot Tables in the workbook

  1. #1
    Registered User
    Join Date
    02-01-2006
    Posts
    27

    Macro that willl affect all Pivot Tables in the workbook

    Hi - trying to write macro that will affect ALL existing pivot tables in my workbook (not just the first one) to change their layout from the default Compact to my preference of Tabular layout. The macro below works HOWEVER it changes only the first pivot table in the workbook. Been playing with some For Each loops, but no luck so far....I'm missing something. Need help to write code to convert ALL Pivot tables' compact layout to the Tabular layout for all present pivot tables in the file, please. Thank you!

    Please Login or Register  to view this content.
    Last edited by jeffreybrown; 09-14-2013 at 09:58 AM. Reason: As per Forum Rule #3, please use code tags…Thanks.

  2. #2
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Macro that willl affect all Pivot Tables in the workbook

    See if this code helps

    Please Login or Register  to view this content.
    Thanks

  3. #3
    Registered User
    Join Date
    02-01-2006
    Posts
    27

    Re: Macro that willl affect all Pivot Tables in the workbook

    Hi fredlo2010 - thanks for your reply! I pasted your code into my macro but nothing at all happens when I run it (it's a global macro-enabled file, so that shouldn't be it). I wonder if the set pt = sh.pivottables(1) part of your suggestion is having an adverse effect (since there are several pivot tables on the worksheet and in the workbook) and the (1) instructs to look at first pivot table?? Thanks again for your assistance

  4. #4
    Registered User
    Join Date
    02-01-2006
    Posts
    27

    Re: Macro that willl affect all Pivot Tables in the workbook

    Hi again fredlo2010 - had a chance to further test your code suggestion, and sure enough, it works great IF there is only one pivot table per worksheet in a workbook (if so, each one on each worksheet is successfully converted to Tabular layout). However, if there are 2 or more pivot tables on a single worksheet in the file, the code won't work at all on any of them! Wondering if you might have a suggestion to tweak the code to address ANY AND ALL pivot tables on all worksheets in the file? Thanks again

  5. #5
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Macro that willl affect all Pivot Tables in the workbook

    Hello ddd,

    Ok it should be working now

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    02-01-2006
    Posts
    27

    Re: Macro that willl affect all Pivot Tables in the workbook

    Thank you in advance, fredlo2010! Code looks like it's gonna do the job...I will give this a try ASAP and will respond again

  7. #7
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Macro that willl affect all Pivot Tables in the workbook

    hello,

    i just realized there was a small flaw in the code

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    02-01-2006
    Posts
    27

    Re: Macro that willl affect all Pivot Tables in the workbook

    Hello fredlo2010 - works wonderfully. I can't thank you enough! Appreciate your time and expertise!!!

  9. #9
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Macro that willl affect all Pivot Tables in the workbook

    You are welcome!

  10. #10
    Registered User
    Join Date
    02-01-2006
    Posts
    27

    Re: Macro that willl affect all Pivot Tables in the workbook

    Why this didn't occur to me earlier!?!?! What about adjusting your code to make it affect ALL Pivot tables but JUST ON THE ACTIVE SHEET? In other words, if there is one or more PTs on whatever sheet is currently active, convert their layout to Tabular WITHOUT affecting other PTs that may be present on the other sheets in the file?

  11. #11
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Macro that willl affect all Pivot Tables in the workbook

    This should take care of that (untested)

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    02-01-2006
    Posts
    27

    Re: Macro that willl affect all Pivot Tables in the workbook

    Hi fredlo2010 - thank you! I just tested it and got a compile Block IF error message (removed the last end if just to see, but it's not working). Any further suggestion, please? Thanks again

  13. #13
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Macro that willl affect all Pivot Tables in the workbook

    I just tested it and got no error. Yet my workbook is empty. can you send a screenshot of the error and line. and if possible a small sample of the workbook?

    Thanks

  14. #14
    Registered User
    Join Date
    02-01-2006
    Posts
    27

    Re: Macro that willl affect all Pivot Tables in the workbook

    Hi Fredlo2010 - I attached a sample test file. There are pivot tables on 2 worksheets. When I run the macro, I want only the PTs on the current active sheet I'm viewing (not the other sheets) to be affected. However, when I run it, I get the following VB error: COMPILE ERROR: END IF WITHOUT BLOCK IF. I've already put the macro in the file so you can run it to test. Many thanks in advance for looking at this
    Attached Files Attached Files

  15. #15
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Macro that willl affect all Pivot Tables in the workbook

    Hi ddd,

    Thanks for the sample it makes debugging a lot easier. All done.

    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    02-01-2006
    Posts
    27

    Re: Macro that willl affect all Pivot Tables in the workbook

    PERFECT! You've been SO helpful.....Thank you very much

  17. #17
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Macro that willl affect all Pivot Tables in the workbook

    I am glad I was able to help

  18. #18
    Registered User
    Join Date
    10-11-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: Macro that willl affect all Pivot Tables in the workbook

    I just happened across this thread. I have been looking for something like this for a while. I appreciate the clean and easy to follow code.
    Thanks!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. locating pivot tables in workbook
    By carlossaltz in forum Excel Charting & Pivots
    Replies: 10
    Last Post: 02-12-2024, 01:44 PM
  2. Replies: 0
    Last Post: 07-25-2013, 05:24 PM
  3. How many pivot tables per sheet or workbook?
    By StudioPhi in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 1
    Last Post: 02-28-2013, 10:08 AM
  4. Replies: 0
    Last Post: 09-22-2012, 07:22 PM
  5. Pivot Tables & Shared Workbook
    By Chard in forum Excel General
    Replies: 1
    Last Post: 05-08-2007, 02:48 AM

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