Macro Run-time Error for a pivot table

jme1013

New Member
Joined
Aug 14, 2010
Messages
19
Hello,

I have a macro that controls 3 different pivot tables for me. It works fine as long as the filter "term" is in the data. The data gets updated monthly and sometimes some of the "terms" that I use to filter with won't have any data for a given month.

When this happens I get the 1004: run-time error Application-defined or object-defined error, due to the Filter "term" being absent.

here's my code...
VBA Code:
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
In this example, if there were no data points in a given month for MXG, then "MXG" will not be in the pivot table to picked, causing the error.

I'd like for it to pick "(blank)" in the absence of "MXG" because "(blank)" is always available.

I'd need it to do this for all 3 pivot tables separately.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Cross-posted here: Runtime Error 1004 - Due to missing data

Note that while we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0
Thank you.

I've cross-posted this trying to cast a wide net.
 
Upvote 0

Forum statistics

Threads
1,214,818
Messages
6,121,725
Members
449,049
Latest member
MiguekHeka

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
Back
Top