+ Reply to Thread
Results 1 to 9 of 9

I think my VBA code is screwing up my PivotTables

  1. #1
    Registered User
    Join Date
    06-28-2013
    Location
    Fort Mill, SC
    MS-Off Ver
    Excel 2010
    Posts
    17

    I think my VBA code is screwing up my PivotTables

    I have a bunch of PivotTables that can be filtered by Month and Year. I wrote a UserForm and macro to let a user change the filtered month and year with just a few clicks of a button. Unfortunately, it seems to have stopped working. I noticed that when I run the macro, it starts changing the actual list of months or years in the PivotTables. Here's the UserForm code:

    Please Login or Register  to view this content.
    And here's an example of the code I use for changing the PTs:

    Please Login or Register  to view this content.
    When I first started this, if I clicked the Month filter on any of those PTs, I could choose from 3 to 7. Now the only options are 5, 10, 11, and Month (which were all the different selections I made in the ComboBoxes). If I choose something other than those, the program throws an error. Basically, I think that when I change the month in the ComboBox and run the macro, it actually changes the contents of the PivotTables.

    Any idea what's going on here and how I can fix this?

  2. #2
    Registered User
    Join Date
    06-28-2013
    Location
    Fort Mill, SC
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: I think my VBA code is screwing up my PivotTables

    Anybody? If I refresh my PivotTables, the report filter fields still don't populate with the proper data. I've checked the data source and it's fine. If I add a new PivotTable from the same external data source, it's fine. Why are these PivotTables broken?
    Last edited by RollerRagerMD; 07-24-2013 at 09:14 AM.

  3. #3
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: I think my VBA code is screwing up my PivotTables

    Can you upload an example? I noticed you are using excel 2010 which means you have access to slicers. Have you considered just making the month or year available to slicers? That would entirely remove the need for the user form and provide the same functionality to your users.

    If you can upload a simple example, I'd be glad to have a look.
    Remember, saying thanks only takes a second or two. Click the star icon(*) below the post you liked, to give some Rep if you think an answer deserves it.

    Please,mark your thread [SOLVED] if you received your answer.

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

    Re: I think my VBA code is screwing up my PivotTables

    Josie

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

  5. #5
    Registered User
    Join Date
    06-28-2013
    Location
    Fort Mill, SC
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: I think my VBA code is screwing up my PivotTables

    Well I couldn't figure out how to fix the PivotTables so I just rebuilt them, but I did figure out how to stop VBA from messing with them. I also made my code a lot shorter... I had written each individual table's modification and then realized it'd be much easier and faster with a loop.

    Please Login or Register  to view this content.
    The bolded lines are what appear to keep it from going haywire. I don't know why it was screwing them up before, I think it had to do with a filter already being applied. It wasn't clearing the filters before. Next step: error handling for when a chosen month is out of a table's range...

  6. #6
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: I think my VBA code is screwing up my PivotTables

    I made up this quick example, you can connect slicers to multiple PTs (asked about in PM). You do that by going to the "Slicer Tools" > Options > Pivot Table Connections. There, you just check which tables are connected to a slicer.

    SEE OPTIONS 2 TAB for multiple tables on the same set of slicers


    ALSO: Option1 uses extra data columns to make Month and Year a slice-able field. In Option2 I just used grouping to get the Month/Quarter/Year without needing to add any columns to the data table. Grouping dates like this is yet another built in excel feature.



    Check this out. Glad you got the code to work, and you many need no further help, but I really wanted to post this example because this is a perfect case for slicers :D
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    06-28-2013
    Location
    Fort Mill, SC
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: I think my VBA code is screwing up my PivotTables

    Sweet. That's very helpful. However, I should explain that different PTs are connected to different data sources. For instance, one set of PTs is connected to "CPB Freight" and another is connected to "MDF Freight." When I go into the PT Connections window, it only lets me select the CPB PTs if I started the slicer on a CPB table. Any way around that?

  8. #8
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: I think my VBA code is screwing up my PivotTables

    You would need one set for each data source, so if you have many sources it might get messy.

  9. #9
    Registered User
    Join Date
    06-28-2013
    Location
    Fort Mill, SC
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: I think my VBA code is screwing up my PivotTables

    Yeah, that's what I was thinking in our convo. Personally I'd be fine with it but I'm fairly certain management would ask me to "optimize" the interface

+ 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. [SOLVED] Simple IF fx help - I keep screwing something up...
    By brose99 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-16-2012, 02:45 PM
  2. Selection.Filldown keeps screwing up
    By lordterrin in forum Excel General
    Replies: 2
    Last Post: 10-24-2012, 03:04 PM
  3. VBA Code Is Screwing Up A Formula
    By frith in forum Excel General
    Replies: 1
    Last Post: 11-13-2011, 12:43 AM
  4. Compile error screwing with me
    By MDC in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-08-2006, 04:55 PM
  5. PivotCaches and pivotTables by code
    By arides in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-05-2005, 10:09 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