+ Reply to Thread
Results 1 to 6 of 6

Pivot items filtered by named range

  1. #1
    Registered User
    Join Date
    08-12-2009
    Location
    Antwerp, Belgium
    MS-Off Ver
    Excel 2003
    Posts
    3

    Pivot items filtered by named range

    I've been looking all over the internet yesterday to find some vba code which is able to have my pivotitems in my pivottable filtered by a named range containing multiple items.

    Furthermore, the code should be applied whenever the contents of the Named range are changed.

    Pivottable is called ptProductAnalysis (resides on "NPI_GroupDB" worksheet)
    Pivotfield is called "Group"
    Named range is "NPI_GroupOffset"

    Basically, whatever is in NPI_GroupOffset (NamedRange) should be displayed in ptProductAnalysis (Pivottable) in the Group (Pivot field)

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Pivot items filtered by named range

    A sample file would generally help in these instances but I wonder if perhaps something along the lines of the below would work for you ?

    Please Login or Register  to view this content.
    The above should be placed in the Sheet object that contains the named range NPI_GroupOffset - to ensure this is placed correctly right click on the tab name in XL select View Code and paste above into resulting window - thereafter ensure Macros are enabled. As you alter the content of the named range you should find the PT Field is filtered according to the content of the named range.

  3. #3
    Registered User
    Join Date
    08-12-2009
    Location
    Antwerp, Belgium
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Pivot items filtered by named range

    That works perfectly, but apparently I think a line needs to be added somewhere so the macro starts of by setting the pivot items to show all, otherwise you get errors in certain cases.

    What code do I need to add for this?

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Pivot items filtered by named range

    hmm... in "theory" the code should be cycling all the items in the Field (visible or not) and setting visible status of said item to True/False depending on whether or not the item is listed in the named range - that said it was coded off the cuff so I have not tested it!

    Could you post a sample please ?

  5. #5
    Registered User
    Join Date
    08-12-2009
    Location
    Antwerp, Belgium
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Pivot items filtered by named range

    I found the solution,

    I just added the following before you have it match the named range with the pivot items:

    Please Login or Register  to view this content.
    It does give an error when the contet of the named range is empty, but normally, in the report I'm building, it is not possible to have nothing selected. I thought your code would take care of that, but unfortunately it doesn't:

    Please Login or Register  to view this content.

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Pivot items filtered by named range

    If you want a tailored solution you will need to provide a representative sample I'm afraid - you don't for ex. specify how the Named Range is defined so it's not clear if this is dynamic or not. There's not really a great deal we can do with limited info / nothing against which to test the concept etc...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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