Consulting

Results 1 to 20 of 32

Thread: Pivot Tables: error in 'Field.CurrentPage = NewCat'

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    Apr 2021
    Posts
    45
    Location

    Pivot Tables: error in 'Field.CurrentPage = NewCat'

    Hello,

    I have a VBA that automatically updates a pivot table filter on my worksheet based on the value you enter in cell A1 in that sheet. Or at least it should do. The code used to work but now I get an error message saying:

    'run time error 1004: application-defined or object-defined error'

    When I click on 'debug' it highlights the bold part in yellow: [Red Line:SamT)


    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
     
    'This line stops the worksheet updating on every change, it only updates when cell
    'A1:B2 is touched
    If Intersect(Target, Range("A1:B2")) Is Nothing Then Exit Sub
     
    'Set the Variables to be used
    Dim pt As PivotTable
    Dim Field As PivotField
    Dim NewCat As String
     
    'Here you amend to suit your data
    Set pt = Worksheets("Client").PivotTables("PivotTable7")
    Set Field = pt.PivotFields("TEBUD")
    NewCat = Worksheets("Client").Range("B1").Value
     
    'This updates and refreshes the PIVOT table
    With pt
    Field.ClearAllFilters
    
    
    Field.CurrentPage = NewCat
    pt.RefreshTable
    End With
     
    End Sub
    does anyone know why this is happening and how to fix it?
    Last edited by SamT; 04-15-2021 at 11:42 AM.

Posting Permissions

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