VBA & Macro Problems

Create a WPS Excel Macro to Filter by Active Cell Value

Ayan MasoodAyan Masood Nov 13, 2026 869 views

Question details

The user wants to automate worksheet filtering so that the selected cell determines the filter value for its column.

Create an Excel Macro to Filter Using the Active Cell in WPS Spreadsheets
Product
WPS Spreadsheets
Device & OS
not provided
Scenario
The user is working in a worksheet and wants a reusable macro that filters the current column by the active cell value.
Observed behavior
The filter should update automatically when the macro is run with a cell selected.
Before you start

Open the workbook in WPS Spreadsheets and make sure the Developer tab is visible. Select a cell in the column that you want to filter before running the macro.

Solution 1Recommended

Add a Reusable ActiveCell AutoFilter Macro in WPS Spreadsheets

Use this solution when you want the selected cell to set the filter criterion automatically for its column.

This VBA macro reads ActiveCell.Value and passes it to AutoFilter, so the filter updates each time you run the macro.

Adjust the range and Field number to match your worksheet layout.

1
Open the VBA editor

In WPS Spreadsheets, click the Developer tab and select View Code, or press Alt+F11 to open the Microsoft Visual Basic for Applications editor.

2
Insert a module

In the Project Explorer, right-click the workbook project, choose Insert, and then select Module.

3
Paste the filter macro

Paste the following code into the module: Sub FilterByActiveCell() Dim rng As Range Set rng = ActiveSheet.Range("A1:D100") If ActiveCell.Value <> "" Then rng.AutoFilter Field:=ActiveCell.Column, Criteria1:=ActiveCell.Value End If End Sub

4
Save the workbook as macro-enabled

Save the file as an Excel Macro-Enabled Workbook (.xlsm) or WPS-compatible macro-enabled format so the VBA code is retained.

5
Run the macro

Select a cell in the column you want to filter, go to Developer > Macros, choose FilterByActiveCell, and click Run.

Filter applied from active cell: The active cell value is used as the filter criterion for its column.
WPS Spreadsheets Macro Solution

Filter by Active Cell with a WPS Spreadsheets VBA Macro

WPS Spreadsheets supports VBA macros, so you can automate active-cell filtering directly in a familiar worksheet environment. The macro reads the selected cell and applies AutoFilter without switching to Microsoft Excel.

  1. 1. Install WPS Office Free: Download WPS Office Free from the official WPS website and install WPS Spreadsheets.
  2. 2. Open the workbook: Launch WPS Spreadsheets and open the Excel file that contains the data to filter.
  3. 3. Create the macro: Press Alt+F11 to open the VBA editor, insert a module, and paste the FilterByActiveCell code.
  4. 4. Run the macro: Select the cell value to filter by, click Developer > Macros, choose FilterByActiveCell, and select Run.
Filter data instantly from the active cell without manually opening filter dropdowns.Uses familiar VBA AutoFilter code that is compatible with Excel macro-enabled workbooks.Works with Excel Macro-Enabled Workbook (.xlsm) files and other Excel-compatible formats.Free, lightweight WPS Office suite with a familiar spreadsheet interface.
microsoft office alternative - wps office

Frequently Asked Questions

Can I use this active cell filter macro in WPS Spreadsheets?

Yes. WPS Spreadsheets supports VBA macros. Open the VBA editor with Alt+F11, insert a module, and run the macro from Developer > Macros.

How does the macro know which value to use?

The macro uses ActiveCell.Value as the Criteria1 argument and ActiveCell.Column as the AutoFilter Field, so it filters based on the selected cell.

Why does the macro show an error when the active cell is outside the range?

The active cell column must exist inside the specified AutoFilter range. Adjust the range to include that column or use a range that starts in column A.

Which file format should I save to keep the macro?

Save as an Excel Macro-Enabled Workbook (.xlsm) or the WPS macro-enabled format. Ordinary .xlsx files do not retain VBA macros.

How do I enable macros if WPS blocks them?

Check the macro security settings under the Developer tab or Trust Center, and only enable macros for workbooks you trust.