+ Reply to Thread
Results 1 to 9 of 9

Pivot Tables-How to ignore?

  1. #1
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Pivot Tables-How to ignore?

    I run a series of macros which open workbooks, manipulate the pivot tables therein, and bring the data into another workbook, wherin the data is massaged and then a pivot table is created. With my code below I turn off what I don't want to see. However, if one of the items I list as "Visible = False" doesn't appear in the list of PivotItems, the code fails with an error code 1004, "Unable to get the PivotItems property of the PivotFields class". How do I configure it so that if the pivot item doesn't exist just ignore it?
    Please Login or Register  to view this content.
    Last edited by jomili; 10-19-2011 at 11:14 AM.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Pivot Tables-How to ignore?

    I think I'd do it with an error catcher:

    Please Login or Register  to view this content.
    This will ignore the specific error of no pivot items in the pivot fields class, but will display all other errors before exiting the sub. One other way to do it would probably be to loop through all the pivot items and make sure that each one you want to turn off is present before turning it off. It'd probably go something like this:

    Please Login or Register  to view this content.
    You'd have to play around with the PivotItems collection to get the exact syntax.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Pivot Tables-How to ignore?

    Dave,

    I opted for the error catcher, assuming it would be faster. However, it doesn't appear to be working correctly. When I run it I get the msgbox (the "else" part of your code) saying
    Please Login or Register  to view this content.
    I don't understand why that would still be appearing.

  4. #4
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Pivot Tables-How to ignore?

    You need to make sure the error description text EXACTLY matches the error description you get when running without the error catcher.

    One way to do this, run the code without the error catcher and when you get an error, type "print err.description" into the immediate window and press enter. Take the text it returns and paste it back into your code after "If err.Description = ". Does that do it?

  5. #5
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Pivot Tables-How to ignore?

    Well, I didn't see any visible difference in the error code, but pasting it back in DID make a difference; when I reenabled the error checker and ran it again I got an error code with only a "0" in it. Now what in the world does that mean?

  6. #6
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Pivot Tables-How to ignore?

    You need to exit the sub before your code gets down to the error catcher. For example, if your code is this:

    Please Login or Register  to view this content.
    You need to add an Exit Sub where I commented so the error catcher code only runs if there is an error.

  7. #7
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Pivot Tables-How to ignore?

    A-ha! That "exit sub" did the trick. Now we're cookin'!

    Thanks so much for walking me through this. Another trick I can add to my tools. Thanks loads!

  8. #8
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Pivot Tables-How to ignore?

    You're welcome John. It is great to work with someone who responds promptly, uses the right amount of detail when describing issues, and is always courteous.

  9. #9
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,952

    Re: Pivot Tables-How to ignore?

    Thanks for commenting on my better qualities. I think they're all nicely balanced by the fact that I'm constantly in need of help so am always pestering the folks on this forum. Thanks to people like you I'm actually learning a bit of this, a little bit at a time.

+ 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