Pivot table refresh/filter with VBA

Egg 'n' Bacon
5StarLounger
Posts: 736
Joined: 18 Mar 2010, 11:05

Pivot table refresh/filter with VBA

Post by Egg 'n' Bacon »

One of our fairly complex spreadsheets has a number of pivot tables, that are refreshed through VBA.
Unfortunately, (blanks) are filtered and if there is new 'row header' data, these do not appear on the refreshed pivot.

The problem I have is My VBA skills are pretty rudimentary and I am struggling.
I have tried various things, but usually end up with an error.

Attached is an idea of what we have.
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78679
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Pivot table refresh/filter with VBA

Post by HansV »

I'd remove the filter, then add the filter for (blank) again:

Code: Select all

Sub Macro1()
'
    '==============================
    'Refresh pivot & clear blanks
    '==============================
    With ActiveSheet.PivotTables("PivotTable1")
        .PivotCache.Refresh
        With .PivotFields("Loc")
            .ClearAllFilters
            .PivotItems("(blank)").Visible = False
        End With
    End With
End Sub
Best wishes,
Hans

Egg 'n' Bacon
5StarLounger
Posts: 736
Joined: 18 Mar 2010, 11:05

Re: Pivot table refresh/filter with VBA

Post by Egg 'n' Bacon »

That looks promising.
I'll give it a go later.

Thank you