Consulting

Results 1 to 6 of 6

Thread: Pivot table filter based on value using VBA code

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Post Pivot table filter based on value using VBA code

    Hi All,

    The given below code filter the Pivot table based on cell value. I created this in module. But I want to implement this in specific worksheet "Market_MU Summary",

    as I run this in "private sub procedure" with "change" event, the code just keep refreshing the pivots and doesn't stop even it hangs the excel.

    Please any help on this.

    Option Explicit
    
    Sub Worksheet_Change1111()
        Dim a As String
        Dim pt As PivotTable
        Dim ws As Worksheet
    Set ws = ThisWorkbook.Sheets("Market_MU Summary")
        Set pt = ws.PivotTables("PivotTable3")
    ' Activate the worksheet containing the PivotTable
        'ThisWorkbook.Worksheets("Market_MU Summary").Activate
    ' Get the value from cell C3
        a = Worksheets("Market_MU Summary").Cells(3, 33).Value
    ' Loop through all PivotTables in the active sheet
        For Each pt In ActiveSheet.PivotTables
            With pt.PivotFields("Uniq Count")
                ' Check if "Uniq Count" is a valid field in the PivotTable
                If .Orientation = xlPageField Then
                    .ClearAllFilters
                    .CurrentPage = a
                End If
            End With
        Next pt
    End Sub
    Last edited by Aussiebear; 09-30-2023 at 05:28 AM. Reason: Added code tags to supplied code

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •