+ Reply to Thread
Results 1 to 4 of 4

Pivot table not updating when using data validation

Hybrid View

  1. #1
    Registered User
    Join Date
    07-21-2015
    Location
    West Midlands
    MS-Off Ver
    2010
    Posts
    43

    Pivot table not updating when using data validation

    Hi,
    I have some code that is trying to update my pivot table, but when I select a dropdown i have to come off it and click the cell to update the data. Please could anyone help? I have searched but cant find anything that matches what I am trying to do. All i want it for it to update when i select one of the dropdowns. The code is below.

    Thank you

    Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    If Intersect(Target, Range("B3")) Is Nothing Then Exit Sub
     
    Dim pt As PivotTable
    Dim Field As PivotField
    Dim NewCat As String
    
    
    Set pt = Worksheets("Pivot").PivotTables("PivotTable1")
    Set Field = pt.PivotFields("Month Name")
    NewCat = Worksheets("Report").Range("B3").Value
    With pt
    Field.ClearAllFilters
    Field.CurrentPage = NewCat
    pt.RefreshTable
    End With
    
    End Sub
    Last edited by aimone111; 07-30-2015 at 04:45 AM. Reason: Code Was not code tagged

  2. #2
    Forum Contributor
    Join Date
    06-30-2015
    Location
    Netherlands
    MS-Off Ver
    2013 / 2016 / 365
    Posts
    146

    Re: Pivot table not updating when using data validation

    Hi,

    When posting a question next time try to comply to forum rules. Reading code without code tags is sometimes undoable.
    Having said that, try this code. Please remember to change the fieldname to apply the filter to!


    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim ws As Worksheet
        Dim pt As PivotTable
        Const strField1 As String = "enter your own field name here!!"
        
        On Error Resume Next
        Application.EnableEvents = False
        Application.ScreenUpdating = False
        
        If Target.Address = "$B$3" Then
            For Each ws In ThisWorkbook.Worksheets
                For Each pt In ws.PivotTables
                    With pt.PageFields(strField1)
                    .ClearAllFilters
                    .CurrentPage = Target.Value
                    End With
                Next pt
            Next ws
        End If
       
        Application.EnableEvents = True
        Application.ScreenUpdating = True
    End Sub

  3. #3
    Registered User
    Join Date
    07-21-2015
    Location
    West Midlands
    MS-Off Ver
    2010
    Posts
    43

    Re: Pivot table not updating when using data validation

    Thank you Joris, your a star, that worked perfect, I will make sure I do that from now on with code tags.

    Thanks
    Dustin

  4. #4
    Forum Contributor
    Join Date
    06-30-2015
    Location
    Netherlands
    MS-Off Ver
    2013 / 2016 / 365
    Posts
    146

    Re: Pivot table not updating when using data validation

    Hi Dustin,

    Please mark issue as solved if you're happy with the provided solution.

+ 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. Problems updating Pivot Table with new data
    By Andres007 in forum Access Tables & Databases
    Replies: 1
    Last Post: 07-30-2014, 09:39 AM
  2. Help with Pivot table data updating issue
    By lgc.fico in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 05-24-2013, 10:56 PM
  3. Updating Two Pivot Filters based on Two Data Validation Cell Text
    By garam082981 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-13-2012, 01:21 PM
  4. Replies: 0
    Last Post: 09-01-2011, 04:25 PM
  5. updating a pivot table with current year's data
    By Takeadoe in forum Excel General
    Replies: 2
    Last Post: 03-30-2006, 04:30 PM
  6. Updating Pivot Table Column Date Data
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-18-2005, 11:05 AM
  7. Updating source data while in Pivot Table
    By Carim in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-27-2005, 10:06 AM

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