Create a simple VBA Macro to select the pivot filter and uncheck "-" and "(Blanks)" from the filters option

chrisforeal

New Member
Joined
Feb 26, 2015
Messages
1
Create a VBA Macro to select the pivot filter and uncheck "-" and "(Blanks)"

I am stumped and need assistance. I created a pivot table, a chart, and pivot slicers. When a pivot slicer field is selected the pivot table below changes based on the pivot slicer criteria, but because there are "-" and "(Blanks)" in the Row label Column (Cell A23) of the pivot table, this causes the bar chart data to skewed to the left. In order to make the chart more presentable along the x-axis I need to select the Row Label filter in the pivot table and unselect "-" and "(Blanks)"for the chart to return to normal along the x-axis. The x-axis are dates in the format of YYYY.

How can I create a VBA macro that when I select any pivot slicer criteria, to automatically click on the pivot table row labels filter button and unselect just "-" and "(blanks)" and leave just the date ranges?

357r09x.jpg


Listed below is my VBA macro and hope someone who is an EXCEL SUPERSTAR can solve this!

----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Sub Macro7()
'
' Macro7 Macro
'
' Keyboard Shortcut: Ctrl+g
'
ActiveSheet.Range("$A$23:$D$1056").AutoFilter Field:=1, Criteria1:="<>-", _
Operator:=xlOr, Criteria2:="<>="
End Sub


I want this macro to click on the Row Labels Filter on the pivot table (pivot table name is 'PivotTable1) and uncheck just "=" aka (blanks) or "=-", but when i run this macro i keep getting "Run-Time Error '1004': Autofilter Method Range Class failed.

Thanks in advance!
Chris
 
Last edited:

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,217,366
Messages
6,136,128
Members
449,993
Latest member
Sphere2215

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