Fix VBA Pie Chart Not Updating with PivotTable Filters
Question details
The user needs to resolve an issue where pie charts created via VBA do not visually update to reflect the newly filtered values of their associated PivotTables.
- Product
- Spreadsheet (VBA/Macros)
- Device & OS
- not provided
- Scenario
- Running a VBA macro to create multiple PivotTables and connected pie charts, and attempting to filter the data by specific categories like Apple, Pear, or Banana.
- Observed behavior
- The VBA code successfully applies the filters to the PivotTables, but the connected pie charts fail to reflect the expected filtered data visually.
Before modifying your VBA code, ensure that your workbook calculation mode is set to Automatic and that you have enabled macros in your Trust Center settings.
Force PivotTable and Chart Refresh Using VBA
Explicitly command the PivotCache and Chart objects to refresh within your macro to ensure visual updates are triggered after applying filters.
Sometimes Excel or WPS Spreadsheet processes VBA code faster than the graphical interface can render. When a PivotTable is filtered via VBA, the connected PivotChart might not pull the updated data immediately without an explicit refresh command.
Press ALT + F11 to open the Visual Basic for Applications (VBA) editor and locate the module containing your PivotTable macro.
Right after the line of code where you apply the filter to the PivotField, add 'ActiveSheet.PivotTables("YourPivotTableName").PivotCache.Refresh' to update the data cache.
Insert 'Application.Calculate' and 'DoEvents' at the end of your charting loop. This forces the application to process pending graphical updates before the macro finishes.
Troubleshoot Using a Simplified Sample Workbook
Isolate the VBA issue by creating a minimal sample file. Complex workbooks often contain hidden structural issues that prevent charts from updating.
Automate Data and Charts Seamlessly with WPS Spreadsheet
WPS Spreadsheet provides a robust, highly compatible environment for running VBA macros, managing dynamic PivotTables, and automating chart generation without graphical lag.
- 1. Enable Developer Tools: Open WPS Spreadsheet, go to the Developer tab, and click 'Macros' to manage your VBA scripts.
- 2. Insert PivotTables: Navigate to the Insert tab, select 'PivotTable', and define your data source to start analyzing your data.
- 3. Create Dynamic Charts: With the PivotTable selected, insert a Pie Chart. Any VBA filters applied to the PivotTable will seamlessly update the connected chart.

Frequently Asked Questions
Why do my PivotCharts not update automatically when the underlying data changes?
PivotCharts are linked to PivotTables, which rely on a data cache. If the source data changes, you must manually refresh the PivotTable (Data > Refresh All) or use the VBA command 'ActiveWorkbook.RefreshAll' for the chart to reflect the new data.
Can I filter a PivotChart directly using VBA instead of filtering the PivotTable?
No, PivotCharts act as a visual representation of the PivotTable. To filter the chart, you must apply the filter to the PivotFields of the associated PivotTable in your VBA code.
Does WPS Office support VBA for PivotTables?
Yes, WPS Office fully supports VBA macros, including the creation, manipulation, and filtering of PivotTables and PivotCharts. You can run your existing .xlsm files directly in WPS Spreadsheet.
What does the DoEvents function do in VBA charting?
The DoEvents function temporarily yields execution so that the operating system can process other events. In charting, it allows the application to catch up and redraw the charts before the macro moves on to the next line of code.




