PivotFields property

FrancescoAFR

New Member
Joined
Aug 5, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,

I have a problem with this code:
VBA Code:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)

    Dim ws As Worksheet
    Dim pv As PivotTable
    Dim pf As PivotField

    Set ws = ThisWorkbook.Worksheets("Atleti e Media")
    Set pv = ws.PivotTables("PerATleta")
    Set pf = pv.PivotFields("Media Ore Settimanale")
    
    For Each pf In pv.PivotFields
    
    pf.ClearAllFilters
    pf.PivotItems("00:00:00").Visible = False

End Sub

To try and identify the problem, I checked through the Locals to ensure the pivot table is assigned correctly and I also tried using a
VBA Code:
For Each pf In pv.PivotFields
before setting pf, but the error message remains the same:
"Unable to get the PivotFields property of the PivotTable class"
Thanks
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Are you sure the pivot table has a field called "Media Ore Settimanale" exactly? Check for leading or trailing spaces and for non-printing characters like chr(160) (the non-breaking space)
 
Upvote 0
I changed the name of the field to "Sum of Media Ore Settimanale" and now it works, but the code stops at the next instruction. How can I remove any existing filters and then set one to hide all times with the value "00:00:00"?
Following the current version of the macro:
VBA Code:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)

    Dim ws As Worksheet
    Dim pv As PivotTable
    Dim pf As PivotField
    Dim pi As PivotItem

    Set ws = ThisWorkbook.Worksheets("Atleti e Media")
    Set pv = ws.PivotTables("PerAtleta")
    Set pf = pv.PivotFields("Sum of Media Ore Settimanale")

    pf.ClearAllFilters
    pf.PivotItems("00:00:00").Visible = False

End Sub
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top