Others

How to Filter Excel Data to Exclude Values and #N/A Errors Using VBA

Elise WilliamsElise Williams Nov 3, 2026 870 views

Question details

The user needs to write a VBA macro to filter a dataset to exclude both specific ordinary values and formula errors like #N/A.

How to Filter Excel Data to Exclude Values and #N/A Errors Using VBA
Product
Excel
Device & OS
not provided
Scenario
Automating data filtering via VBA to clean up a spreadsheet by hiding rows that contain specific unwanted numbers or #N/A error values.
Observed behavior
While standard not-equal criteria in VBA AutoFilter successfully hide ordinary values, using Criteria1:="<>#N/A" fails to exclude #N/A formula errors.
Before you start

Ensure that the Developer tab is enabled in your ribbon to access the Visual Basic Editor, and confirm the exact column index that contains the target data and potential #N/A errors.

Solution 1Recommended

Use a Helper Column and VBA to Filter Out #N/A Errors

Since AutoFilter struggles to interpret error values directly via VBA string criteria, creating a temporary helper column with the ISNA function is the most reliable method to identify and filter them out.

VBA treats AutoFilter criteria as strings. Because #N/A is an error type rather than a text string, the standard not-equal operator does not evaluate it properly. Using a helper column transforms the error check into a simple boolean (TRUE/FALSE) value.

1
Insert a Helper Column Formula

In an empty adjacent column (e.g., Column C), insert a formula to check for the error, such as `=ISNA(B2)`, and fill it down to the bottom of your dataset.

2
Apply AutoFilter for FALSE

Write a VBA script to apply an AutoFilter on this new helper column. Use `Criteria1:="FALSE"` to display only the rows that do not contain the #N/A error.

3
Execute Code and Manage Layout

Run the macro. The #N/A errors will be hidden. You can then add code to hide the helper column from view to keep the spreadsheet clean.

Use a Helper Column and VBA to Filter Out #N/A Errors
Formula Alternative: You can also use `=ISERROR(B2)` instead of ISNA if you want to filter out other types of formula errors like #DIV/0! or #VALUE! simultaneously.
Advanced Data Filtering

Filter and Manage Data with Macros in WPS Spreadsheet

WPS Office Spreadsheet provides robust support for VBA and macros, allowing you to easily automate data filtering tasks, handle errors like #N/A, and manage large datasets smoothly.

  1. 1. Open Your Dataset: Launch WPS Spreadsheet and open the file containing the data and errors.
  2. 2. Access the Developer Tab: Navigate to the Developer tab on the ribbon and click on 'Visual Basic' or 'Macros'.
  3. 3. Run the Filtering Macro: Paste your AutoFilter and helper column VBA code into the editor and press Run to instantly filter out the unwanted values and #N/A errors.
Excellent compatibility with Microsoft Excel VBA macros and AutoFilter methods.Flawlessly handles complex formulas like ISNA and ISERROR.Native support for .xlsx and .xlsm macro-enabled formats.Lightweight, fast, and free to download.
microsoft office alternative - wps office

Frequently Asked Questions

Why doesn't Criteria1:="<>#N/A" work in Excel VBA AutoFilter?

AutoFilter in VBA treats criteria as text strings. Since #N/A is a specialized error data type rather than a standard text string, the filter fails to evaluate it correctly, meaning the error rows remain visible.

Can I filter out blank cells using VBA AutoFilter?

Yes, you can easily filter out blank cells in a specific column by setting your VBA AutoFilter criteria to `Criteria1:="<>"`.

How do I clear an active AutoFilter using VBA?

You can clear existing filters and show all data by using the command `ActiveSheet.ShowAllData`. Alternatively, you can toggle the filter off by using `Selection.AutoFilter` without any parameters.