+ Reply to Thread
Results 1 to 10 of 10

Refresh Pivot - caught in a loop

  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,956

    Refresh Pivot - caught in a loop

    I'm having trouble with the "Refresh" part of the macro below. When the macro triggers, if I watch it, the screen just keeps flickering. When I hit escape, I get a Run-Time 1004 error saying "RefreshTable method of PivotTable Class failed". It's a simple bit of code, so I don't know why it would be messing up. Any help troubleshooting this is greatly appreciated.
    Please Login or Register  to view this content.
    Last edited by jomili; 11-18-2011 at 09:43 AM.

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

    Re: Refresh Pivot - caught in a loop

    Okay, I discovered the cause of the problem, but not the solution. The last part of my macro pastes the updated data back into the "MFR Adjustments" sheet, which then triggers the WorksheetActivate event, which retriggers the macro, and round and round it goes.

    I don't know how to proceed from here, so if anyone has an idea now would be the time to suggest it.

    Thanks,
    John

  3. #3
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Refresh Pivot - caught in a loop

    Then insert at the top of your macro

    Please Login or Register  to view this content.
    And at the buttom
    Please Login or Register  to view this content.
    Please take time to read the forum rules

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

    Re: Refresh Pivot - caught in a loop

    Hmm, it helps, but it's not there.

    A little background: my users will make changes to their Projections page. ProjPivot is a sheet containing a pivot based on that Projections page. When they make a change, at some point they'll want to go to the MFR Adjustments page to see how that affects everything on that page. So, when they activate MFR Adjustments, I want my macro to run, to update all the values.

    What's happening now (after the Enable Events changes):

    If ProjPivot is my active page, and I run the macro, it runs perfectly.

    If Projections is my active page, and I enter a change, and then select MFR Adjustments, the macro does not work correctly.

    It doesn't generate an error, but columns H and I in the ProjPivot (and so columns A and B in MFR Adjustments) only contain a header, with nothing underneath.

    Any other ideas?

  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,956

    Re: Refresh Pivot - caught in a loop

    Okay, I found a way, but I don't like it.

    After "Enable Events false" if I Activate my ProjPivot sheet, then run the code, then activate MFR Adjustments, then re-enable events, it works.

    I really don't want to activate and reactivate my sheets like that, but I can live with it if I have to.

  6. #6
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Refresh Pivot - caught in a loop

    Just a recommendation. Instead of using Range, try cell(x,y) to extract the last row number

    For example,
    LR = Cells(rows.count, "X").end(xlup).row

  7. #7
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Refresh Pivot - caught in a loop

    The problem lies with the Worksheet_change-event.

    Maby if you macro gave some indication to the Worksheet_change event it would be better.

    At the top off your macro place
    Please Login or Register  to view this content.
    At the buttom

    Please Login or Register  to view this content.
    In your worksheet_change event place an outer if
    If the range specified above = 1 then dont do anything
    Else Do whats there.

    Steffen Thomsen

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

    Re: Refresh Pivot - caught in a loop

    Jie Jenn,
    So I'd replace X with the column number I want to use for my last row, right? I tested it, and it seems to work just fine, but why would it be superior in any way?

    Steffen,
    I tried your suggestion. If I take away my two "Activate" statements, then whether I use your suggestion or not the macro still has the same problem.

  9. #9
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Refresh Pivot - caught in a loop

    Try refering the full path to the data whenever you have a range.

    Sheets(name).Range(range) and so on, it's somewhere in these references the code fails!

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

    Re: Refresh Pivot - caught in a loop

    Well, I had a well thought out answer, articulated beautifully, and it disappeared into cyberspace somewhere, so here's my cheap and easy final response: I went another route, using VLookups instead on the MFR Adjustments page, which means I don't have to do any page changing, which takes away the problem of getting stuck in a loop. So, life is good, God is in charge, and all is well.

    Thanks for all the help, and JieJenn, I'm still curious as to why your lastrow formula would be superior.

    Thanks,
    John

+ 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