+ Reply to Thread
Results 1 to 2 of 2

Autofilter a sheet that includes a Pivot Table

  1. #1
    Forum Contributor
    Join Date
    08-12-2019
    Location
    NYC
    MS-Off Ver
    2019
    Posts
    155

    Autofilter a sheet that includes a Pivot Table

    Hi All,

    I'm a bit struggling with the following situation. I have a sheet that includes a pivot table. Given that the pivot table can dynamically change in size depending on the number of inputs it contains, my sheet includes 1000 empty lines (the pivot table can contain as much as 1000 elements) so it leaves enough room for the pivot table to expand. Obivously, I don't want to let 1,000 lines displayed if the pivot table is smaller than that. To solve this issue, I created a range that includes the pivot table + one additional column which is used as the filter. This column can be either 1 or 0 depending on the size of the pivot table. By auto-filtering this column, it automatically hides the lines that are not used by the pivot table, resizing my sheet to an appropriate dimension.

    Attached is an example of what I'm trying to achieve (not that 0 and 1 are plugged for simplicity). I would assume that by using the following VBA, it would automatically filter the range called "table" using column 3 (which is the list of 1 and 0) and hide lines:
    Please Login or Register  to view this content.
    However, this is not the case and I get an error message telling me: "Run-time error "1004": Autofilter method of Range class failed".

    I've used this technique with success in other sheets of my workbook but it does not seem to work in this sheet in particular. I dont know if this is related to the pivot table and I'm not sure to know how to resolve that.

    Note that I get an error message in my example file. In my actual file, I dont get an error but nothing happens either so I guess something's wrong anyway.

    Thanks for the help
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    08-12-2019
    Location
    NYC
    MS-Off Ver
    2019
    Posts
    155

    Re: Autofilter a sheet that includes a Pivot Table

    For anyone interested, I wasn't able to have the aforementioned piece of code work with a pivot table in the middle. But an alternative way that seems to work is to manually filter the range (which works even if there's a pivot table inside) and then using the following code to refresh:
    Please Login or Register  to view this content.
    The refresh does not seem to have an issue with the pivot table

    Thanks

+ 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. Autofilter Pivot table item
    By Manuel Casal in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-18-2020, 06:23 AM
  2. [SOLVED] how to autofilter a pivot table?
    By fluffyvampirekitten in forum Excel Charting & Pivots
    Replies: 6
    Last Post: 07-20-2015, 02:51 AM
  3. Macro to autofilter pivot table for last 60 days
    By oldmanexcel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-12-2013, 03:06 AM
  4. Macro Help Needed - Link Pivot Table Filter to Regular Table AutoFilter
    By ycx1129 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-11-2011, 12:54 PM
  5. Pivot Table with AutoFilter
    By raggatip in forum Excel General
    Replies: 1
    Last Post: 01-16-2011, 07:35 PM
  6. How to autofilter a pivot table
    By jordan.lawrance in forum Tips and Tutorials
    Replies: 0
    Last Post: 05-20-2009, 06:56 AM
  7. [SOLVED] Autofilter always includes last line of data irrespective of filter
    By Peter in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-26-2006, 10:15 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