+ Reply to Thread
Results 1 to 6 of 6

PIVOT table autofilter based on data validation cell selection

Hybrid View

fredstyler PIVOT table autofilter based... 02-15-2011, 10:50 AM
DonkeyOte Re: PIVOT table autofilter... 02-15-2011, 11:43 AM
fredstyler Re: PIVOT table autofilter... 02-15-2011, 12:32 PM
DonkeyOte Re: PIVOT table autofilter... 02-16-2011, 03:36 AM
fredstyler Re: PIVOT table autofilter... 02-16-2011, 09:12 AM
DonkeyOte Re: PIVOT table autofilter... 02-16-2011, 09:23 AM
  1. #1
    Registered User
    Join Date
    11-28-2008
    Location
    The Netherlands
    Posts
    14

    PIVOT table autofilter based on data validation cell selection

    Hi,

    I have a question about pivot tables

    I attached a simplified example, question:

    how can I link the value of the drop down box to the PIVOT table, so that the PIVOT tables shows the selection of the drop down box, without manually selecting it in the PIVOT table itself,

    Thanks in advance
    Attached Files Attached Files
    Last edited by fredstyler; 02-15-2011 at 11:06 AM. Reason: Attachment was not correct

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

    Re: PIVOT table autofilter based on data validation cell selection

    Using your example, right click on Sheet1 select View Code and paste below into resulting window.
    Thereafter alterations to B2 should update the Pivot accordingly.

    Note: when saving you must save in a macro enabled format and remember to enable Macros when re-opening going forward.

    If using XL2010 (unknown) consider using a Slicer.

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim rngDV As Range
        On Error GoTo ExitPoint
        Application.EnableEvents = False
        Set rngDV = Range("B2")
        If Not Intersect(Target, rngDV) Is Nothing Then
            PivotTables("PivotTable1").PivotFields("Countries").CurrentPage = rngDV.Value
        End If
    ExitPoint:
        Set rngDV = Nothing
        Application.EnableEvents = True
    End Sub

  3. #3
    Registered User
    Join Date
    11-28-2008
    Location
    The Netherlands
    Posts
    14

    Re: PIVOT table autofilter based on data validation cell selection

    Thanks!

    I am not so familiar yet with VBA in Excel, but do you know how it looks like if you have several PIVOTS on sheet 2 and 3, but the selection of countries remains on sheet 1?

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

    Re: PIVOT table autofilter based on data validation cell selection

    Yes, but you need to provide some more information ... are you update all Pivots on Sheets 2 & 3 ?

    The Change event will still reside on Sheet1 but obviously you need to iterate the Pivots on other sheets.

    Roughly speaking:

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim rngDV As Range, ws As Worksheet, PT As PivotTable
        On Error GoTo ExitPoint
        Application.EnableEvents = False
        Set rngDV = Range("B2")
        If Not Intersect(Target, rngDV) Is Nothing Then
            For Each ws In Sheets(Array("Sheet2", "Sheet3"))
                For Each PT In ws.PivotTables
                    With PT
                        On Error Resume Next
                        .PivotFields("Countries").CurrentPage = rngDV.Value
                        On Error GoTo ExitPoint
                    End With
                Next PT
            Next ws
        End If
    ExitPoint:
        Set rngDV = Nothing
        Application.EnableEvents = True
    End Sub
    however, this does not account for multi page selections etc... which may or may not be a requirement.

    post a sample to demonstrate requirements as nec.

  5. #5
    Registered User
    Join Date
    11-28-2008
    Location
    The Netherlands
    Posts
    14

    Re: PIVOT table autofilter based on data validation cell selection

    Hi,

    The simplified version looks like this (attachment). There are more pivots on sheet2 (Pivots), but they all relate back to the country which is selected on the sheet1 (Country). The data comes from the same file, but is collected on the sheet called Data.

    Thanks for all your help
    Attached Files Attached Files

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

    Re: PIVOT table autofilter based on data validation cell selection

    I believe the code provided previously does what you requested, however, you obviously need to modify the Sheets Array to reflect your own set up - I used Sheet2 & Sheet3 as these were referred to in prior post.

    The code (provided previously and amended per above) should reside in Country Sheet Object in VBE (ie location of Data Validation cell)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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