Dynamic Pivot Table - Uncheck Blanks VBA

rikvny02

Board Regular
Joined
Aug 9, 2022
Messages
78
Office Version
  1. 365
Platform
  1. Windows
My data is always changing but I never need blanks within the filter. Id like to uncheck blanks each and every time I refresh my pivot table. The below code works great within a table but, It will not work on a pivot table. I receive a 400 error code. Can someone help me manipulate the code to work with a pivot table.

Sub FilterDynamicRng1() 'Excel VBA dynamic range
Range("a1", Range("a" & Rows.Count).End(xlUp)).AutoFilter 1, "<>"
End Sub

1662738140046.png
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
By recording a macro while filtering (blank) from a Pivot Table, I get...
VBA Code:
ActiveSheet.PivotTables("PivotTable1").PivotFields("Pay Code").PivotFilters.Add2 Type:=xlCaptionDoesNotEqual, Value1:=""
 
Upvote 0
z51 - your code absolutely works. However, every time I run the macro I receive a error. Any Ideas?
1662753349397.png


1662753393019.png
 
Upvote 0
Try adjusting "ActiveSheet" to your sheet name, e.g. Sheets("Sheet1")
As well as the PivotTable name (might not be "PivotTable1"
And finally the PivotFields name to your field name.
 
Upvote 0
Still receiving the error. I've used every combination I can possibly think of. the PivotFields("row labels") was used as well as pivotfields("Pay Code").
1663096943562.png


Sub pcfilter() 'Excel VBA dynamic range
Sheets("Report - Hours by Pay Code").PivotTables("PivotTable3").PivotFields("row labels").PivotFilters.Add2 Type:=xlCaptionDoesNotEqual, Value1:="(blank)"

End Sub
 
Upvote 0
The below code work by hiding the blanks but id rather see the blank UNCHECKED


With Sheets("report - hours by pay code").PivotTables("PivotTable3").PivotFields("Pay Code")
.PivotItems("(blank)").Visible = False
End With
 
Upvote 0

Forum statistics

Threads
1,215,641
Messages
6,125,982
Members
449,276
Latest member
surendra75

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