0

I make a query with connections in data model then i make some measures and make some pivot table to excel sheet with filter field.

now i want to connect my pivot tables with VBA to clear or select all filter in all PVT fields based on a dropdown list in a cell

Private Sub CommandButton1_Click()
    
    Dim Password As String
    Dim A As String
    Dim PT As PivotTable
    Dim PF As PivotField
    
    Password = InputBox("Kindly Enter Password", "Hello")
    
    If Password = Sheet1.Range("N2").Value Then
        
        Sheet4.Visible = xlSheetVisible
        Sheet4.Select
        
        Sheet5.Visible = xlSheetVisible
        Sheet5.Select
        
        ThisWorkbook.Worksheets("PVT QTY").Activate
        
        A = Worksheets("PVT QTY").Cells(1, 2).Value
        
        For Each PT In ActiveSheet.PivotTables
            
            **   With PT.PivotFields("Location")**
            
            PF.ClearAllFilters
            .CurrentPage = A
            
        End With
        
    Next
    
Else
    
    MsgBox "Password Is Incorrect! Kindly Try Again Or Back To M Adel ", vbCritical, "Wrong password"
    
End If

End Sub

But I get this error

But I Get this Error

James Z
  • 12,209
  • 10
  • 24
  • 44

0 Answers0