+ Reply to Thread
Results 1 to 10 of 10

(Macro) clear filter and refresh Pivot Table data without using ActiveSheet.PivotTables

  1. #1
    Forum Contributor MGadAllah's Avatar
    Join Date
    04-13-2008
    Location
    Sheet1
    MS-Off Ver
    365,2307,16.0.16626.20170,64bit
    Posts
    190

    (Macro) clear filter and refresh Pivot Table data without using ActiveSheet.PivotTables

    The workbook I've includes several sheets, and each sheet includes a Pivot Table.
    I've gave a name for each Pivot Table in each sheet.
    Now I am making a macro to clear filter and refresh each pivot table in each sheet but I want to do it at once.
    Can I make the macro without using "ActiveSheet."
    and only add the Pivot Table name ?
    ActiveSheet.PivotTables("PivotTableName").ClearAllFilters
    The result I am looking for is to refresh each sheet and clear filter for each sheet.
    So I want to determine the pivot table name in each sheet and then choose to clear filter and refresh at once.
    Last edited by MGadAllah; 09-03-2017 at 03:15 PM.

  2. #2
    Forum Contributor MGadAllah's Avatar
    Join Date
    04-13-2008
    Location
    Sheet1
    MS-Off Ver
    365,2307,16.0.16626.20170,64bit
    Posts
    190

    Re: (Macro) clear filter and refresh Pivot Table data without using ActiveSheet.PivotTable

    I can not post any more threads
    Did I violated anything
    \1

    Attachment 536435
    Last edited by MGadAllah; 09-03-2017 at 05:59 PM.

  3. #3
    Forum Contributor MGadAllah's Avatar
    Join Date
    04-13-2008
    Location
    Sheet1
    MS-Off Ver
    365,2307,16.0.16626.20170,64bit
    Posts
    190

    Re: (Macro) clear filter and refresh Pivot Table data without using ActiveSheet.PivotTable

    - test repost -

    Hi,

    I've set the following names to 3 cells in Sheet1


    CalenderPreviousName ... A1
    CalenderCurrentName ... B1
    CalenderNextName ... C1


    I've filled:

    2016 in A1
    2017 in B1
    2018 in C1

    Obviously I've did that to save time creating the same file next year and only file the following years later on like 2017, 2018, 2019 in A1, B1, C1

    Then I've created a table in the same Sheet1 "$A$3:$P$19"

    There is a filed in this table for DATE and its cell formatted as date.

    Then I've created a Pivot Table in Sheet2using the Table in Sheet1

    Now when I open the PivotTable and open the filter menu for Date filed I've found 5 items ( < 2016 , 2016 , 2017 , 2018 , > 2018 ) .

    I want to make a macro to choose only the items represent CalenderPreviousName, CalenderCurrentName, CalenderNextName.

    When I recorded a macro and tried to edit it I've found the recorded code includes the value of the cells "2016, 2017, 2018" and I did tried to replace it with CalenderPreviousName, CalenderCurrentName, CalenderNextName but it resulted with an error.

    So how to set this type of macro?

  4. #4
    Registered User
    Join Date
    02-13-2015
    Location
    Brazil
    MS-Off Ver
    2010
    Posts
    2

    Re: (Macro) clear filter and refresh Pivot Table data without using ActiveSheet.PivotTable

    Hey MGadAllah,

    If all you want to do is pass the value in the cells to the macro, use in your code Sheets("Name of your sheet).Range("Cell Address").Value.
    I believe in your case would be Sheets("Sheet1").Range("A1").Value, Sheets("Sheet1").Range("B1").Value and Sheets("Sheet1").Range("C1").Value.

  5. #5
    Forum Contributor MGadAllah's Avatar
    Join Date
    04-13-2008
    Location
    Sheet1
    MS-Off Ver
    365,2307,16.0.16626.20170,64bit
    Posts
    190

    Re: (Macro) clear filter and refresh Pivot Table data without using ActiveSheet.PivotTable

    I want to pass the value of the cell to use the name I've set for it.
    I've attached the original file
    I am sorry you will find it in Arabic but I can tell you what sheets to use
    Open the 1st sheet to your left, then click on cell A3 you will be directed to the sheet (3rd sheet) where I will fill in the data I will use as a source for pivot table (I've created a connection using the data in this table as the source for the pivot table).
    Now to the 1st sheet to your left, then click on cell A4, you will see the years listed in the first column.
    I want to make the macro to list only the iems represent the previous, the current, the next years as I've mentioned in the earlier post.
    Attached Files Attached Files
    Last edited by MGadAllah; 09-03-2017 at 06:38 PM.

  6. #6
    Forum Contributor MGadAllah's Avatar
    Join Date
    04-13-2008
    Location
    Sheet1
    MS-Off Ver
    365,2307,16.0.16626.20170,64bit
    Posts
    190

    Re: (Macro) clear filter and refresh Pivot Table data without using ActiveSheet.PivotTable

    Hope any one may help

  7. #7
    Forum Contributor MGadAllah's Avatar
    Join Date
    04-13-2008
    Location
    Sheet1
    MS-Off Ver
    365,2307,16.0.16626.20170,64bit
    Posts
    190

    Re: (Macro) clear filter and refresh Pivot Table data without using ActiveSheet.PivotTable

    -later edit-
    This is the macro I've recorded
    Please Login or Register  to view this content.
    So I do not want to use the <6/30/2016 or >6/2/2018 but I want to use the NAME I've set for it, which are :
    CalenderPreviousName or CalenderCurrentName or CalenderNextName

    The reason is that later on if I want to work for later consequence years, I want everything to be correctly sorted without editing anything, and just fill in the correct years in the 3 cells
    CalenderPreviousName ... A1
    CalenderCurrentName ... B1
    CalenderNextName ... C1

    So how to sort it correctly into the macro?

    Thanks

  8. #8
    Registered User
    Join Date
    02-13-2015
    Location
    Brazil
    MS-Off Ver
    2010
    Posts
    2

    Re: (Macro) clear filter and refresh Pivot Table data without using ActiveSheet.PivotTable

    Hello again MGadAllah,

    In this case where you want to pass the value of a named range in your code, all you gotta do is use Range("Name of your range").Value.
    So, as your example, you would have:

    A1 = Range("CalenderPreviousName")
    B1 = Range("CalenderCurrentName")
    C1 = Range("CalenderNextName")

    I've opened your worksheet in my machine and sadly, due to language dificulties, I couldn't understand your data.
    Even though, I think I could guess what you wanted to do, so I've made a little sample sheet and wrote a bit of code that I think will help you.
    In this case, I think the best approach would be to use the same name for all year field in all pivot tables and update the setting of the filter on that field on all tables.
    In the Data sheet I've named cells N1 to N3 with the names you used on your named ranges.

    This is the code I've used, and I'm attaching the sample data below. Hope it helps you.

    Please Login or Register  to view this content.
    Best regards!
    Attached Files Attached Files

  9. #9
    Forum Contributor MGadAllah's Avatar
    Join Date
    04-13-2008
    Location
    Sheet1
    MS-Off Ver
    365,2307,16.0.16626.20170,64bit
    Posts
    190

    Re: (Macro) clear filter and refresh Pivot Table data without using ActiveSheet.PivotTable

    Thanks for replying me
    I've recreated the whole work book with English items instead of Arabic.
    Now you can open and read and understand
    In the report sheet, when you open the Years filter you can see 3 years which are 2016-20017-2018
    In the daily Entries sheet a the top you can find 3 cells named:
    CalenderPreviousYear
    CalenderCurrentYear
    CalenderNextYear
    So the macro I want to make to filter the years I want it to include the names instead of values.
    I'm creating a new sheet each new year, so I want to just fill in the years in these 3 cells without changing anything in the pivot table or the macro I will create.
    This is why I want to make the macro include Name instead of its Value
    This is the macro I've recorded
    Please Login or Register  to view this content.
    So it contains dates which will not work later on if I changed years to 2017-20018-2019
    This is why I've asked about a way to include the name instead of value.
    I am searching since yesterday and can not find a way to replace PivotItem with something else
    Also tried to play with XlPivotFilterType as I've posted about it here bu no luck at all.
    I can use he NAME I've set for the cells in any equation as fine.
    I hope that I was able to clear my point.
    Thanks
    Attached Files Attached Files

  10. #10
    Forum Contributor MGadAllah's Avatar
    Join Date
    04-13-2008
    Location
    Sheet1
    MS-Off Ver
    365,2307,16.0.16626.20170,64bit
    Posts
    190

    Re: (Macro) clear filter and refresh Pivot Table data without using ActiveSheet.PivotTable

    Hope any one may help

+ 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] VBA to clear filter on pivot table row labels
    By bhenlee in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-28-2015, 01:06 PM
  2. ActiveSheet.PivotTables => How to do it for custom sheet? (replace ActiveSheet)
    By chrisignm in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-03-2014, 03:22 PM
  3. Refresh pivot table without updating filter
    By Draagslag in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 04-23-2014, 09:35 AM
  4. Macro to refresh pivot table and update data source
    By TBO in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-01-2013, 01:09 PM
  5. [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
  6. Excel 2007 : How to Clear Pivot Table Filter?
    By dmweinst in forum Excel General
    Replies: 2
    Last Post: 10-01-2009, 01:31 PM
  7. Pivot Table Filter Refresh Issue
    By Roachman3700 in forum Excel General
    Replies: 0
    Last Post: 11-25-2008, 05:58 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