+ Reply to Thread
Results 1 to 25 of 25

VBA Pivot Refresh

  1. #1
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    VBA Pivot Refresh

    I have the following code which will loop through each pivot item and mark the listed criteria as FALSE, then for everything show them as TRUE,

    When i run the code i get an error on this line - Run-time error '1004':

    Unable to set the Visible property of the PivotItem class

    Please Login or Register  to view this content.
    Full code of this section is

    Please Login or Register  to view this content.

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA Pivot Refresh

    are you sure there is data for that item?
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA Pivot Refresh

    Yes, the items listed i am filtering out of the pivot then marking everything else as visible

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA Pivot Refresh

    that's not what I asked

  5. #5
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA Pivot Refresh

    Which item were you referring to?

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA Pivot Refresh

    the one for which the error occurs

  7. #7
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA Pivot Refresh

    The error occurs on trying to select all the other pivot items as visible after select the name criteria as not visible

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA Pivot Refresh

    so the error occurs for every single other item?

  9. #9
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA Pivot Refresh

    Yes, i've tried changing the word True to Yes, or visible or active but no luck

  10. #10
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA Pivot Refresh

    I need to see a sample workbook please

  11. #11
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA Pivot Refresh

    As requested.
    Attached Files Attached Files

  12. #12
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA Pivot Refresh

    does that fail for you? it works for me

    by the way, are you aware that this line
    Please Login or Register  to view this content.
    does not test for items containing those values (MOECA et al)? it checks for those exact strings

  13. #13
    Forum Contributor
    Join Date
    04-25-2013
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    150

    Re: VBA Pivot Refresh

    It seems like this is what you're looking for:

    Please Login or Register  to view this content.
    This will test for pivot items containing your values.

  14. #14
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA Pivot Refresh

    Joseph,

    The code runs, it just doesn't apply the logic to the pivot items...

  15. #15
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA Pivot Refresh

    that is not what you said at the beginning of the thread-you said the code caused errors! I mentioned the issue with your logic and djdjdj provided one way of correcting that

  16. #16
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA Pivot Refresh

    Yes it did have an error which was corrected on the advice, the code ran but didn't apply the logic, now i've tried djdjdj code and it still error's on;

    Please Login or Register  to view this content.

  17. #17
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA Pivot Refresh

    I switched your code to
    Please Login or Register  to view this content.
    and it ran without error on your sample file

  18. #18
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA Pivot Refresh

    I now have an Invalid or unqualified reference for;

    Please Login or Register  to view this content.

  19. #19
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: VBA Pivot Refresh

    as did I in the workbook you posted originally-I simply added a With Activesheet...End With block to it for testing

  20. #20
    Forum Contributor
    Join Date
    04-25-2013
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    150

    Re: VBA Pivot Refresh

    Using your sample workbook, this code runs and filters your pivot table without error. Just copy and paste it in:

    Please Login or Register  to view this content.
    You had an "End With" at the bottom of your code which caused an error. I took it out and the code runs fine.

  21. #21
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA Pivot Refresh

    Thanks, i've tried to run it again with your changes and get the following message;

    "Unable to get the PivotFields property of the pivottable class"

  22. #22
    Forum Contributor
    Join Date
    04-25-2013
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    150

    Re: VBA Pivot Refresh

    Can you attach the worksheet you're using? It's obviously different from your sample sheet. Here's your sample sheet with the code pasted in; it runs without error and filters according to what I understand is your logic.
    Attached Files Attached Files

  23. #23
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA Pivot Refresh

    My pivot is exactly the same other than it has 40000 lines of data, the sample i gave you was a small extract of it.

    Could that be the issue as the data is so large?

  24. #24
    Forum Contributor
    Join Date
    04-25-2013
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    150

    Re: VBA Pivot Refresh

    I think that if your data was too large Excel would freeze rather than causing the script to error. If you open the sample workbook that I uploaded (two posts up), does the script run and filter like you want it to?

  25. #25
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA Pivot Refresh

    Yes it does, that's why i can't understand why it won't work on my full amount of data...

+ 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. Refresh pivot -> refresh Histogram
    By magnus101 in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 08-14-2012, 11:51 AM
  2. [SOLVED] Using VBA to change a pivot table filter, refresh the report and set up a refresh delay
    By Bonnister in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-18-2012, 10:43 AM
  3. Replies: 2
    Last Post: 10-25-2010, 11:31 AM
  4. Pivot table refresh
    By Eleanor M in forum Excel General
    Replies: 0
    Last Post: 01-30-2006, 01:55 PM
  5. [SOLVED] pivot refresh clears pivot fields?
    By Leejo in forum Excel General
    Replies: 0
    Last Post: 10-13-2005, 11:05 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