VBA & Macro Problems

How to Use VBA to Filter WPS Spreadsheets Pivot Slicers to a Rolling Six-Month Period

Algirdas JasaitisAlgirdas Jasaitis Nov 13, 2026 869 views

Question details

The user needs to create a VBA command button that refreshes WPS Spreadsheets PivotTables and filters the connected date slicers so multiple worksheets show only the most recent six months.

How to Use VBA to Filter WPS Spreadsheets Pivot Slicers to a Rolling Six-Month Period
Product
WPS Office Spreadsheets
Device & OS
not provided
Scenario
The user manages dashboards with PivotTables and slicers spread across several worksheets and wants to automate a rolling six-month view after the source data changes.
Observed behavior
Date slicers currently require manual adjustment after refresh, so the worksheets can show an outdated or inconsistent six-month window.
Before you start

Before adding VBA, confirm that all PivotTables and slicers are based on the same source-data date field and that the date column is formatted as a real date in WPS Spreadsheets.

Solution 1Recommended

Use a VBA Command Button to Apply a Rolling Six-Month Slicer Filter

This is the most reliable approach when you want one button to refresh all PivotTables and update each date slicer to the latest six-month window.

The exact VBA code depends on your PivotTable names, slicer cache names, and source-data date field. The routine should be adapted to the names in your workbook, and all date fields must be consistent so the slicer can filter each PivotTable correctly.

1
Enable the Developer tab and add a command button

In WPS Spreadsheets, open the ribbon options to enable the Developer tab, then click Insert > Command Button and draw the button on the worksheet that will control the filter.

2
Open the button click event in the VBA editor

Right-click the command button and choose View Code, or press Alt+F11 to open the VBA editor and select the sheet module where the button was added.

3
Add the rolling six-month VBA filter routine

Write a subroutine that captures the latest date, calculates DateSerial(Year(Date), Month(Date) - 5, 1) as the start of the six-month window, refreshes each PivotTable by name, and then assigns the visible items to each SlicerCache date field.

4
Run the button and verify each worksheet

Return to WPS Spreadsheets, click the command button, and verify that the PivotTables refresh and every date slicer displays only the most recent six-month period.

Use a VBA Command Button to Apply a Rolling Six-Month Slicer Filter
Replace names before running: Update the PivotTable names, slicer cache names, and date field names in the VBA routine to match your workbook. If the source data uses different date formats, normalize them into one date column first.
WPS Spreadsheets VBA

Use WPS Spreadsheets to Run VBA for Rolling Six-Month Pivot Slicers

WPS Spreadsheets supports the VBA editor and macro-enabled workbooks, so you can add a command button, refresh PivotTables, and filter date slicers to the latest six months without switching to a paid Office suite.

  1. 1. Open the macro-enabled workbook: Launch WPS Spreadsheets and open the .xlsm file that contains the PivotTables and slicers you want to automate.
  2. 2. Insert a command button: Enable the Developer tab, click Insert > Command Button, and draw the button on the sheet that should control the rolling filter.
  3. 3. Open the VBA editor and add the filter code: Right-click the button and choose View Code, then create a subroutine that refreshes the PivotTables and applies the DateSerial rolling six-month range to each SlicerCache.
  4. 4. Run the macro and confirm the slicers: Click the button in the worksheet and verify that all selected worksheets show only the most recent six months.
  5. 5. Save as a macro-enabled workbook: Save the file as a macro-enabled workbook type so the VBA button remains available for future refreshes.
Run VBA macros directly in WPS Spreadsheets to automate rolling date slicers.Open and edit Excel .xlsm and .xlsx workbook files with existing PivotTables and slicers.Free, lightweight Office suite with a familiar ribbon and VBA editor.Refresh multiple worksheets and slicer caches from one command button.
microsoft office alternative - wps office

Frequently Asked Questions

Why does the slicer not change to the rolling six months after I run the macro?

Usually the macro applies the filter before the PivotTable is refreshed, or the SlicerCache name does not match the code. Refresh the PivotTable first, then assign the visible items to the correct SlicerCache, and make sure the source range includes the latest dates.

Which VBA function should I use to calculate the six-month start date?

Use DateSerial(Year(Date), Month(Date) - 5, 1) to return the first day of the month five months before the current month, giving a six-month window when combined with the latest date.

Can one VBA button update slicers on multiple worksheets in WPS Spreadsheets?

Yes. The button can loop through the worksheet or PivotTable names, refresh each one, and apply the same date range to each connected slicer cache as long as the date field exists in all source data.

What should I check if WPS Spreadsheets hides the Developer tab?

Enable it from the ribbon options or Settings: right-click the ribbon, choose Customize Ribbon, and select Developer so the Insert > Command Button controls and VBA editor are available.