Results 1 to 5 of 5

Thread: Filter Pivot Table Based On Selected Value And Show All Results Though VBA

Threaded View

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

    Smile Filter Pivot Table Based On Selected Value And Show All Results Though VBA

    Hi All,

    Please find the excel file in which you can filter your result in pivot table according to dropdown selection and find the code give below:

    Code:
    Sub ShowAll()
    
        Dim pt As PivotTable, pi As PivotItem
        Dim xlCalc As XlCalculation
        
        Set pt = Sheet1.PivotTables("PivotTable1")
        
        pt.ManualUpdate = True
    
        With Application
            xlCalc = .Calculation
            .Calculation = xlCalculationManual
            .ScreenUpdating = False '
        End With
        
        On Error Resume Next
        
        For Each pi In pt.PivotFields("StaffCode").PivotItems
            pi.Visible = True
        Next pi
        
        On Error GoTo 0
    
        pt.ManualUpdate = False
    
        With Application
            .Calculation = xlCalc
            .ScreenUpdating = True
        End With
    
    End Sub
    
    
    Sub ShowPivotFilterResult()
    
        Dim pt As PivotTable, pi As PivotItem
        Dim xlCalc As XlCalculation
        
        
        Set pt = Sheet1.PivotTables("PivotTable1")
        
        pt.ManualUpdate = True
        
        With Application
            xlCalc = .Calculation
            .Calculation = xlCalculationManual
            .ScreenUpdating = False '
        End With
        
        On Error Resume Next
        
        For Each pi In pt.PivotFields("StaffCode").PivotItems
            pi.Visible = True
        Next pi
        
        On Error GoTo 0
    
    
        On Error Resume Next
        
        For Each pi In pt.PivotFields("StaffCode").PivotItems
            If pi.Value = Range("rngVALUE").Value Then
                pi.Visible = True
            Else
                pi.Visible = False
            End If
        Next pi
        
        On Error GoTo 0
    
        pt.ManualUpdate = False
    
        With Application
            .Calculation = xlCalc
            .ScreenUpdating = True
        End With
    
    End Sub
    Attached Files Attached Files
    Last edited by hanishgautam; 07-08-2013 at 09:09 PM. Reason: Code Tags Added

Similar Threads

  1. Extract Selected Data from Excel - Advanced Filter
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 2
    Last Post: 01-10-2014, 10:49 AM
  2. Replace Pivot Table Source Range with New Address VBA
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 1
    Last Post: 04-25-2013, 07:51 PM
  3. Replies: 3
    Last Post: 03-05-2013, 03:57 PM
  4. Filter more than one pivot table at one time
    By larryt1940 in forum Excel Help
    Replies: 8
    Last Post: 05-04-2012, 06:45 PM
  5. Replies: 9
    Last Post: 03-13-2012, 01:27 PM

Posting Permissions

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