Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I'm having an issue where I have a macro control 3 pivot tables.

Everything works fine except when no data is available in one of the tables.

In my example code, I'm filtering for "MXG". If there isn't any "MXG" data for a given month, the macro throws the runtime error.

I'd like for the macro to select "(blank)" in the absence of "MXG".

Thanks for any help.

Sub MXG()
'
' MXG Macro
' Get MXG Data
'

'
    Sheets("My Data").Select
    ActiveSheet.PivotTables("PivotTable13").PivotFields("Work Center"). _
        ClearAllFilters
    ActiveSheet.PivotTables("PivotTable13").PivotFields("Work Center").CurrentPage _
        = "MXG"
    ActiveSheet.PivotTables("PivotTable14").PivotFields("Org").ClearAllFilters
    ActiveSheet.PivotTables("PivotTable14").PivotFields("Org").CurrentPage = "MXG"
    ActiveSheet.PivotTables("PivotTable15").PivotFields("Org").ClearAllFilters
    ActiveSheet.PivotTables("PivotTable15").PivotFields("Org").CurrentPage = "MXG"
End Sub


What I have tried:

I've tried iferror solution to no avail
Posted
Updated 6-Jan-20 12:22pm
Comments
ZurdoDev 6-Jan-20 16:37pm    
Which line of code throws the error?

1 solution

My apologies for answering just with text, I’m answering from my phone.

I have 3 lines that are similar, each one refers to a different pivot table. I get the error if “MXG” is missing from the list.

VB
ActiveSheet.PivotTables("PivotTable13").PivotFields("Work Center").CurrentPage _ = "MXG"


I was trying to get it to recognize if “MXG” was not available to default to “(blank)” as that’s an option that is always available.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900