Automatically refresh pivot table filter to remove spaces and blanks

CaptainGravyBum

Board Regular
Joined
Dec 1, 2023
Messages
76
Office Version
  1. 365
Platform
  1. Windows
Hello,
I have a pivot table with chart in my workbook and there are a lot of empty and (blank) cells in the data reference.
When the data changes I have to go to the filter and select all, before unselecting the empty and (blank) values otherwise it will not select any of the new fields in my pivot.
Is there a way to get excel to do this for me when the sheet is refreshed? I tried recording a macro but that didn't work, I also tried the following VBA, but that doesn't pick up any new fields in my data.

Application.EnableEvents = False
ThisWorkbook.RefreshAll
Application.EnableEvents = True
 
There is a line in the code
VBA Code:
ActiveSheet.Range("$A$10:$T$98").AutoFilter Field:=1, Criteria1:="<>"
replace the range $A$10:$T$98 with yours
I think this is where i'm going wrong, as with the data fields, my range expands when new data is entered so I'm putting the data range as the whole column.
 
Upvote 0

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.
Did you try @RoryA suggestion in Post #7 ?

• Right click on the field that you are filtering out blanks
• Select Field Settings
• Using the tab Subtotals & Filters at the very bottom check the box next to "Include new items in manual filters"

1725977118072-png.116681
 

Attachments

  • 1725977118072.png
    1725977118072.png
    84.3 KB · Views: 16
Upvote 1
Solution
Did you try @RoryA suggestion in Post #7 ?

• Right click on the field that you are filtering out blanks
• Select Field Settings
• Using the tab Subtotals & Filters at the very bottom check the box next to "Include new items in manual filters"

1725977118072-png.116681
To be honest, I didn't really understand how to do this until you sent me the screenshot, so thanks.
I have just tried and unfortunately, when I tick the box it crashes out of the worksheet, no idea why.
 
Upvote 0
I think I've cracked it now, with thanks to everyone's help. I managed to apply the 'include new items' part and alongside the refresh all on the sheet selection it is refreshing all data and including any new items.
Thanks again.
 
Upvote 0

Forum statistics

Threads
1,221,339
Messages
6,159,335
Members
451,555
Latest member
Ragham26

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