VBA to edit PivotTable

ChrisMcIntyre

New Member
Joined
Jan 6, 2022
Messages
29
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi there, and right off the bat, I am still a total newbie to VBA and now Pivot Tables too.

I have the following code setup in my workbook, and it's doing everyting I want except hide the "(blank)" entries.
It should refesh all the tables first, then reset the filters in "Row" field so all items are selected, then it should uncheck anything labelled "(blank)".
Any ideas how I can hide those pesky blanks please?

Thanks, Chris.

Sub REFRESH_PIVOTS()

'Refresh PivotTables

ActiveWorkbook.REFRESHALL

Dim pt As PivotTable
Dim pf As PivotField

Set pt = ActiveSheet.PivotTables("PivotTable9")
Set pf = pt.PivotFields("Row")
With pf
.ClearAllFilters
On Error Resume Next
.PivotItems("(blank)").Visible = False
On Error GoTo 0

End With

End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,181,953
Messages
5,932,931
Members
436,869
Latest member
ABGTH

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
Top