Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pivot Tables and Blanks

Status
Not open for further replies.

EliseFreedman

Programmer
Dec 6, 2002
470
GB
Hi there

I am trying to write a macro to get rid of all the blank rows in my pivot tables. I have several pivot tables on a single worksheet. I am using the following code
Code:
 With ActiveSheet.PivotTables("NumberCommencingPhysio").PivotFields( _
        "Referral Month Number")
                 .PivotItems("(blank)").Visible = False
End With
This code works fine if a blank row exists in the pivot table. However, if there is no blank row then the code crashes.

I have tried enclosing the .pivotItems line within an If statement but that didnt work either
Code:
 With ActiveSheet.PivotTables("NumberCommencingPhysio").PivotFields( _
        "Referral Month Number")
        If .PivotItems("(blank)").Visible = True
         .PivotItems("(blank)").Visible = False
       End if
End With

Does anyone have any ideas


 

Use error handling:
Code:
'turn off error handling
on error resume next

With ActiveSheet.PivotTables("NumberCommencingPhysio").PivotFields( _
        "Referral Month Number")
                 .PivotItems("(blank)").Visible = False
End With
'turn it back on again
on error goto 0

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top