+ Reply to Thread
Results 1 to 16 of 16

VBA refresh all pivot tables in the workbook then select the current month

  1. #1
    Registered User
    Join Date
    08-16-2020
    Location
    USA
    MS-Off Ver
    2016
    Posts
    22

    VBA refresh all pivot tables in the workbook then select the current month

    Hi I'm new to this forum.


    In the attached file, there is tab that is called the "destination" and "destination2" sheet tab. This is basically, where all the pivots are connected to the charts with slicers( sorry, for some reason I wasn't able to copy and paste the slicer on the destination tab so screenshot it to make sure you get the idea behind it). Also, The data will be added to each "source" tab daily...here what I want in the vba code which didn't work for me.


    1. I want to make sure that each time the data is added to the source and source2 tab, that all the pivot tables are refreshed automatically with click button on each sheet with current month selected in the pivot table and filters out the other months
    Last edited by mz_h; 08-19-2020 at 01:19 PM.

  2. #2
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: VBA refresh all pivot tables in the workbook then select the current month

    Hi mz_h

    Does the below macro do what you're looking for ?

    Please Login or Register  to view this content.
    If I was able to help, you can thank me by clicking the * Add Reputation under my user name

  3. #3
    Registered User
    Join Date
    08-16-2020
    Location
    USA
    MS-Off Ver
    2016
    Posts
    22

    Re: VBA refresh all pivot tables in the workbook then select the current month

    Nankw83,

    Thank you so much for your reply! I will try this out and let you know tomorrow, if it works for me. I had another question on another thread for rolling 6 months period to display only on the pivot slicers. Can you please assist with that? I would really appreciate it!!

  4. #4
    Registered User
    Join Date
    08-16-2020
    Location
    USA
    MS-Off Ver
    2016
    Posts
    22

    Re: VBA refresh all pivot tables in the workbook then select the current month

    HI Nankw83,

    I have a question about the code that you sent above. First of all, thank you for a quick response.

    1. My first question is if the "months" has sometimes a different field name...just like the multiple sheets names differ..for example some fields name might be "calldate(month)","months" and when I added these in the code it gave me an error (see below). Can I use a command button or it needs to be in module since when I used the command button it gave me an error? The file is attached

    With Pvt.PivotFields("Months","Calldate(month)")
    .ClearAllFilters


    2. My second question is I have two specific pivot tables that has three months selected and want it to roll 3months at a time with VBA after I refresh with the above code? Can you please assist so basically, whenever the data source is updated the months in the pivot will show only 3 months including the current month.


    Capture_1.PNG
    Last edited by mz_h; 08-17-2020 at 04:32 PM.

  5. #5
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: VBA refresh all pivot tables in the workbook then select the current month

    Hi mz_h & apologies for the late response ... The code I provided in post #2 is based on your original sample file. Regarding your two question,

    1. With Pvt.PivotFields("Months","Calldate(month)") will not work, if you have different fields name in different pivot tables we have to find a work around.
    2. That should be possible but you have to specify which pivot tables that need to be having the 3-month rolling date filter

    I suggest that you make a copy of your original file, change the data to dummy data (keeping the same file structure/pivot tables name ... etc.) & share it with us here so whatever code we provide can work in your original file without hassles

  6. #6
    Registered User
    Join Date
    08-16-2020
    Location
    USA
    MS-Off Ver
    2016
    Posts
    22

    Re: VBA refresh all pivot tables in the workbook then select the current month

    HI Nankw83,

    Hope all is well. I just attached the file above.Attachment 691761 filename(copy and paste from pivot table_Question(2) Regarding my questions above. I have pivot tables with different name fields that I want to refresh to the current month with multiple sheets.

    1. My first question is if the "months" has sometimes a different field name...just like the multiple sheets names differ..for example some fields name might be "calldate(month)","months" and when I added these in the code it gave me an error (see below). Can I use a command button or it needs to be in module since when I used the command button it gave me an error? The file is attached

    With Pvt.PivotFields("Months","Calldate(month)")
    .ClearAllFilters

    2. My second question is I have two specific pivot tables that has three months selected and want it to roll 3months at a time including the current month VBA after I refresh with the above code? Can you please assist so basically, whenever the data source is updated the months in the pivot will show only 3 months including the current month.

  7. #7
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: VBA refresh all pivot tables in the workbook then select the current month

    HOW TO ATTACH YOUR SAMPLE WORKBOOK:

    Fast answers need clear examples. Post a small Excel sheet (not a picture) showing realistic & representative sample data WITHOUT confidential information (10-20 rows, not thousands...) and some manually calculated results. Just before posting, scroll down to GO ADVANCED, click, and then scroll down to MANAGE ATTACHMENTS and click again. Now follow the instructions at the top of that screen.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  8. #8
    Registered User
    Join Date
    08-16-2020
    Location
    USA
    MS-Off Ver
    2016
    Posts
    22

    Re: VBA refresh all pivot tables in the workbook then select the current month

    Hi Oeldere,

    Please find the attached updated workbook. FILENAME ATTACHED IN THE FIRST THREAD of my post-COPY PASTE PIVOT TABLE_QUESTION(2).Xlsm. I would really appreciate the help with my above question.

  9. #9
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: VBA refresh all pivot tables in the workbook then select the current month

    Hi mz_h,

    Apologies I couldn't reply back earlier ... Try the below code & I have also attached the sample file I worked on

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    08-16-2020
    Location
    USA
    MS-Off Ver
    2016
    Posts
    22

    Re: VBA refresh all pivot tables in the workbook then select the current month

    Thank you so much! I will try it and let you know soon!

  11. #11
    Registered User
    Join Date
    08-16-2020
    Location
    USA
    MS-Off Ver
    2016
    Posts
    22

    Re: VBA refresh all pivot tables in the workbook then select the current month

    Hi Nankw83,

    Can you please reattach the file. After I downloaded the file, it won't open at all. I would really appreciate it!

  12. #12
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: VBA refresh all pivot tables in the workbook then select the current month

    Hi mz_h,

    If you are getting a message "We found a problem with some content in [file name]. Do you want us to recover as much as we can ... etc.". Click 'Yes' then you'd probably get another message "Microsoft Excel was attempting to open & repair the file ... etc." & then the file still won't open !

    Once above process is done, go to your downloads folder, right click on the file then click properties & check the last checkbox to "Unblock" where it says "Security: This file came from another computer and might be blocked to help protect this computer"

    I have encountered this issue suddenly yesterday where any downloaded file from the forum won't open & after googling I found this work around. I am still searching why this has happened suddenly & how to prevent it

  13. #13
    Registered User
    Join Date
    08-16-2020
    Location
    USA
    MS-Off Ver
    2016
    Posts
    22

    Re: VBA refresh all pivot tables in the workbook then select the current month

    Nankwe,

    This works perfect! Can I ask you a question from the code you provided in the attachment,just for my understanding, If I want to seperate it out. Which part of the code is doing the the 3 month filtering for image below? Question below with the image?Attachment 692937

  14. #14
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: VBA refresh all pivot tables in the workbook then select the current month

    Can't see the attached image ... The codes loops 4 times, hence For x = 1 to 4 and the below block of code indicates what to do i.e. 1 month or 3 months. So for the first & third loop, it performs the first part of "IF" condition 2 & 4 performs the second part, i.e. 3 months

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    08-16-2020
    Location
    USA
    MS-Off Ver
    2016
    Posts
    22

    Re: VBA refresh all pivot tables in the workbook then select the current month

    Thank you so much for all your help nankwe83!!! I'm new to this forum, how do i write that it is solved?

  16. #16
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: VBA refresh all pivot tables in the workbook then select the current month

    Glad I to help & thanks for the reps

    You can mark this thread as [SOLVED] from the Thread Tools button above your first post

+ 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. auto refresh pivot tables with data source in different workbook
    By mlaxx in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-23-2019, 08:30 AM
  2. VBA CODE to refresh pivot but only current month and future months
    By Jane1980 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-11-2018, 05:29 PM
  3. Replies: 3
    Last Post: 11-18-2015, 02:14 PM
  4. [SOLVED] Refresh all existing Pivot Tables in different Worksheets in a Workbook
    By trizzo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-18-2015, 03:29 PM
  5. [SOLVED] Refresh a date (month) on Several Pivot Tables
    By l.niehues in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-22-2014, 07:26 AM
  6. Refresh all pivot tables in workbook based on cell value
    By ChrisHowk in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-15-2013, 04:19 PM
  7. [SOLVED] Refresh all pivot tables in a workbook
    By nc in forum Excel General
    Replies: 3
    Last Post: 06-22-2005, 02:05 PM

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