简体   繁体   中英

I have a macro to refresh all pivot tables in my workbook, I need to add code to remove (blanks)'s

I have a workbook with multiple pivot tables throughout. I have found some code that works for refreshing all of my pivot tables at once (assigned to a button). But in order for the rest of my calculations to work, I currently have to go to each table and deselect (blank) from the Row Labels filter.

I've tried many options to add code that will also filter out the blanks, but can't seem to get the syntax right.

Here's what I'm currently using to refresh all of my pivot tables; what do I need to add to filter the blanks as well?

Sub RefreshAllPivotTables()
    Dim PT As PivotTable
    Dim WS As Worksheet

    For Each WS In ThisWorkbook.Worksheets
        For Each PT In WS.PivotTables
            PT.RefreshTable
        Next PT
    Next WS
End Sub

Try this. Basically just added the loop through each of the Pivot Fields

Sub RefreshAllPivotTables()

Dim PT As PivotTable
Dim WS As Worksheet
Dim PF As PivotField

    For Each WS In ThisWorkbook.Worksheets
        For Each PT In WS.PivotTables
            PT.RefreshTable
            For Each PF In PT.PivotFields
                On Error Resume Next
                PF.PivotItems("(blank)").Visible = False
            Next PF
        Next PT
    Next WS
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM