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?
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
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?

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: