Excel VBA Filter Multiple Criteria: Examples and Code

VBA & macros · Updated November 19, 2026

To filter by multiple criteria in Excel VBA, use the range’s AutoFilter method: apply one criterion per field for conditions that must all be true, or use Operator:=xlOr / an array of values for alternatives within a field. For example, filter a table to show West-region rows with sales above 1,000 by applying criteria to the Region and Sales fields in turn.

How AutoFilter combines criteria

AutoFilter hides rows that do not meet the selected conditions; it does not delete or rearrange the source data. A field is a column in the filter range, counted from left to right, with the first column numbered 1. The first row of the range should contain headers. If the filter range begins in column A, for example, Field 2 means column B; if it begins in column C, Field 2 means column D.

When you filter different fields one after another, Excel keeps the conditions together as an AND: a row must meet every field’s criterion to remain visible. Within one field, you can instead specify multiple alternatives. The right method depends on whether your logic is “all of these conditions” or “any of these values.”

  • AND across fields: Region is West and Sales is greater than 1,000.
  • OR in one field: Region is West or East.
  • AND or OR in one field: Sales is greater than 1,000 and less than 5,000, or a text field equals one of several specified values.

Filter different columns with AND logic

Suppose a worksheet has headers in A1:D1, with Region in column B and Sales in column D. The following Windows VBA macro filters the range to West and sales greater than 1,000. Its range assumes the data ends at row 100; adjust that endpoint to match the worksheet.

Sub FilterWestHighSales()
    Dim ws As Worksheet
    Dim dataRange As Range

    ' The data has headers in row 1 and runs from A1 through D100.
    Set ws = ThisWorkbook.Worksheets("Data")
    Set dataRange = ws.Range("A1:D100")

    ' Clear existing criteria, if any, then apply both conditions.
    If ws.FilterMode Then ws.ShowAllData
    dataRange.AutoFilter Field:=2, Criteria1:="West"
    dataRange.AutoFilter Field:=4, Criteria1:=">1000"
End Sub

The two calls refer to the same range, so Excel retains the first filter when the second is applied. Rows must satisfy both conditions to be visible. If the data includes more rows, use a range that includes them; rows outside the specified range will not be filtered by this macro. A structured Excel table is often easier to maintain than a hard-coded final row, particularly when data is regularly added.

Match several values in the same field

For a list of alternatives in one column, pass an array to Criteria1 and set Operator to xlFilterValues. This example shows rows whose Region is either West or East. It assumes the same A1:D100 range and header arrangement.

Sub FilterWestOrEast()
    Dim ws As Worksheet
    Dim dataRange As Range

    ' The Region field is the second column of A1:D100.
    Set ws = ThisWorkbook.Worksheets("Data")
    Set dataRange = ws.Range("A1:D100")

    If ws.FilterMode Then ws.ShowAllData
    dataRange.AutoFilter Field:=2, _
        Criteria1:=Array("West", "East"), _
        Operator:=xlFilterValues
End Sub

This is useful for a fixed set of exact text values or categories. The displayed cell values need to match the criteria; extra spaces, different spelling, or inconsistent labels can prevent expected matches. For a short list, type the values directly. For a list that changes, read the criteria from worksheet cells and build the array in VBA rather than editing the macro each time.

Use AND or OR conditions within one field

For two numeric thresholds on the same column, use xlAnd or xlOr. For example, with Sales in the fourth field of A1:D100, greater than 1,000 and less than 5,000 means a value must pass both tests:

Sub FilterSalesRange()
    Dim ws As Worksheet
    Dim dataRange As Range

    ' Sales is Field 4; the criteria form an exclusive interval.
    Set ws = ThisWorkbook.Worksheets("Data")
    Set dataRange = ws.Range("A1:D100")

    If ws.FilterMode Then ws.ShowAllData
    dataRange.AutoFilter Field:=4, _
        Criteria1:=">1000", Operator:=xlAnd, Criteria2:="<5000"
End Sub

The criteria above exclude exactly 1,000 and 5,000. To include the endpoints, use operators such as >= and <=. With xlOr, a row can pass either of the two conditions. For instance, “less than 1,000 or greater than 5,000” selects values outside that interval. AutoFilter supports two criteria in this paired-criteria pattern; for more complicated combinations, use a helper column or Advanced Filter.

Choose the right filtering approach

Before writing code, translate the request into field-level logic. This avoids a common mistake: using OR when the user expects every condition to be true, or applying a second filter in a way that replaces the first. These patterns cover many everyday cases:

  • Several columns, all required: Call AutoFilter once for each field, using the same range.
  • Several exact choices in one column: Use a criteria array with xlFilterValues.
  • A pair of numeric or text comparisons in one field: Use Criteria1, Criteria2, and xlAnd or xlOr.
  • Complex OR logic across different columns: Consider a helper column or Advanced Filter. Standard AutoFilter criteria across fields combine as AND, not as a general expression builder.

For example, “Region is West and Sales exceeds 1,000” is straightforward with two field filters. “Region is West or Sales exceeds 1,000” is different: applying both field filters would require both conditions, excluding rows that meet only one. A helper formula or Advanced Filter criteria range can express that kind of cross-column OR more clearly.

Set up and run the macro safely

On Excel for Microsoft 365 on Windows, save a working copy as an Excel Macro-Enabled Workbook (.xlsm) if the VBA code must be retained. Open the Visual Basic Editor with Alt+F11, choose Insert > Module, paste the procedure into the module, and change the worksheet name, range, field numbers, and criteria as needed. Run it from the editor or from Excel’s macro dialog.

  1. Confirm that the named worksheet exists and that the range includes the header row.
  2. Check each field number relative to the first column in the range, not the worksheet’s column letter.
  3. Save a copy of the workbook before running a macro. VBA actions cannot be undone with Ctrl+Z.
  4. Enable macros only for workbooks and code you trust; macro settings and organizational policies may prevent a macro from running.

On Mac, VBA is available in desktop Excel, but Microsoft documents the Range.AutoFilter method as unsupported on Excel for Mac. Mac users should use a supported alternative such as the Selection.AutoFilter method or work with an Excel table and verify the specific object-model route in their Excel version. Excel for the web can display a workbook containing VBA, but it cannot create, run, or edit VBA macros; use desktop Excel for those tasks.

Common problems and how to fix them

  • Wrong field number: Field numbering starts at 1 for the leftmost column of the selected filter range. It does not necessarily match the worksheet column number.
  • Headers included incorrectly: The first row of the filter range should be the header row. Omitting it can make the first data row act as a header; including title rows can also confuse filtering.
  • Old criteria remain active: A new condition on one field may leave filters on other fields in place. Use ShowAllData when the goal is a fresh result, but only after checking FilterMode as in the examples.
  • Text does not match: Check for trailing spaces, inconsistent spelling, and values that look alike but are stored differently. A cell containing “West ” is not necessarily the same as “West”.
  • Numbers are stored as text: Numeric comparisons may not behave as expected when imported values are text. Convert the source values to numbers or normalize them before filtering.
  • Rows appear to be missing: Inspect hidden rows, the exact filter range, and any filters already applied. AutoFilter hides nonmatches; it does not remove them.

Also distinguish a filter’s visible result from the source data itself. If another procedure processes only visible rows, it must account for hidden rows and filtered ranges deliberately; simply filtering does not guarantee that every later VBA operation will act only on visible cells.

AutoFilter, Advanced Filter, and worksheet formulas

AutoFilter is a good choice for interactive lists and repeatable macros with a modest number of conditions. It is quick to apply, leaves the original records in place, and allows users to inspect the filtered data. Its main limitation is that its criteria model is not designed for every possible combination of AND and OR across many fields.

Advanced Filter is built into Excel and can apply more elaborate criteria using a criteria range, including OR conditions arranged on separate criteria rows. It can filter the original list in place or copy matching records elsewhere. The tradeoff is extra setup: the criteria range must use the same header names as the source, and its row layout determines how conditions combine.

A helper column is often the clearest option when a rule is business-specific or changes often. It can mark each row as eligible based on a combined test, after which VBA filters that helper field. Worksheet formulas, Power Query, or a PivotTable may be better still when the real task is to transform, summarize, or repeatedly import data rather than simply hide rows. Pick the simplest method that expresses the logic accurately and can be maintained by the workbook’s users.

Frequently Asked Questions

How do I apply multiple filters in VBA without clearing the first one?
Call AutoFilter again on the same range, changing the Field and criteria. Excel retains criteria on other fields. Clear existing filters first only when the macro should start from an unfiltered view.

Does Excel VBA use AND or OR between different columns?
AutoFilter criteria applied to different fields combine as AND: each visible row must meet every field’s condition. For OR logic across fields, use a helper column, Advanced Filter, or another method that explicitly evaluates the combined rule.

How do I filter a column for several text values?
Use an array in Criteria1 with Operator:=xlFilterValues. The array holds the allowed values for that one field. Check that the source values match the criteria exactly.

Can AutoFilter handle more than two conditions in one column?
A paired comparison uses two criteria arguments and an AND or OR operator. For a longer list of exact values, use the criteria array pattern. For more involved numeric or mixed logic, consider a helper column or Advanced Filter.

Why does my VBA filter show no rows?
Verify the range, header row, relative field number, and exact criterion. Also check whether numbers are stored as text or labels contain spaces, and whether another field’s existing filter is excluding the same rows.

Key takeaway

For most Excel VBA filtering, apply one AutoFilter criterion per field when all conditions must be met, use a value array for several alternatives in one field, and use paired criteria for a simple same-field comparison. When the requested logic includes complex OR conditions across columns, choose a helper column or Advanced Filter rather than forcing an unclear AutoFilter setup.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.