Author: Oscar Cronquist Article last updated on March 06, 2023 I will in this article demonstrate several techniques that extract or filter records based on two conditions applied to a single column in your dataset. For example, if you use the array formula then the result will refresh instantly when you enter new start and end values.

The remaining built-in techniques need a little more manual work in order to apply new conditions, however, they are fast. The downside with the array formula is that it may become slow if you are working with huge amounts of data.

I have also written an article in case you need to find records that match one condition in one column and another condition in another column. The following article shows you how to build a formula that uses an arbitrary number of conditions: Extract records where all criteria match if not empty

This article Extract records between two dates is very similar to the current one you are reading right now, Excel dates are actually numbers formatted as dates in Excel. If you want to search for a text string within a given date range then read this article: Filter records based on a date range and a text string

I must recommend this article if you want to do a wildcard search across all columns in a data set, it also returns all matching records. If you want to extract records based on criteria and not a numerical range then read this part of this article.

## 1. Extract all rows from a range based on range criteria [Array formula] The picture above shows you a dataset in cell range B3:E12, the search parameters are in D14:D16. The search results are in B20:E22.

Cells D14 allows you to specify the start number, and cell D15 is the end number of the range. Cell D16 determines which column to use in cell range B3:E12.

The result is presented in cells B20:E20 and cells below. The example above shows a start value of 4 and an end value of 6, the column is three meaning the third column in cell range B3:E12.

All records that match range 4 to 6 in cell range D3:D12 are extracted, D3:D12 is the third column in B3:E12.

Update 20 Sep 2017, a smaller formula in cell A20.

Array formula in cell A20:

=INDEX(\$B\$3:\$E\$12, SMALL(IF((INDEX(\$B\$3:\$E\$12, , \$D\$16)< =\$D\$15)*(INDEX(\$B\$3:\$E\$12, , \$D\$16)> =\$D\$14), MATCH(ROW(\$B\$3:\$E\$12), ROW(\$B\$3:\$E\$12)), ""), ROWS(B20:\$B\$20)), COLUMNS(\$A\$1:A1))

### 1.2 How to enter this array formula

1. Select cell A20
2. Paste above formula to cell or formula bar
3. Press and hold CTRL + SHIFT simultaneously
4. Press Enter once
5. Release all keys

The formula bar now shows the formula with a beginning and ending curly bracket, that is if you did the above steps correctly. Like this:

{=array_formula}

Don't enter these characters yourself, they appear automatically.

Now copy cell A20 and paste to cell range A20:E22.

### 1.3 Explaining array formula in cell A20

You can follow along if you select cell A19, go to tab "Formulas" on the ribbon and press with left mouse button on the "Evaluate Formula" button.

#### Step 1 - Filter a specific column in cell range B3:E12

The INDEX function is mostly used for getting a single value from a given cell range, however, it can also return an entire column or row from a cell range.

This is exactly what I am doing here, the column number specified in cell D16 determines which column to extract.

INDEX(\$B\$3:\$E\$12, , \$D\$16, 1)

becomes

INDEX(\$B\$3:\$E\$12, , 3, 1)

and returns C3:C12.

Recommended articles

How to use the INDEX function
Gets a value in a specific cell range based on a row and column number.

#### Step 2 - Check which values are smaller or equal to the condition

The smaller than and equal sign are logical operators that let you compare value to value, in this case, if a number is smaller than or equal to another number.

The output is a boolean value, True och False. Their positions in the array correspond to the positions in the cell range.

INDEX(\$B\$3:\$E\$12, , \$D\$16, 1)< =\$D\$15

becomes

C3:C12< =\$D\$15

becomes

{2; 6; 4; 5; 3; 9; 3; 2; 0; 1}<=6

and returns

{TRUE; TRUE; TRUE; TRUE; TRUE; FALSE; TRUE; TRUE; TRUE; TRUE}.

#### Step 3 - Multiply arrays - AND logic

There is a second condition we need to evaluate before we know which records are in range.

(INDEX(\$B\$3:\$E\$12, , \$D\$16, 1)< =\$D\$15)*(INDEX(\$B\$3:\$E\$12, , \$D\$16, 1)> =\$D\$14)

becomes

({2; 6; 4; 5; 3; 9; 3; 2; 0; 1}< =\$C\$14)*({2; 6; 4; 5; 3; 9; 3; 2; 0; 1}> =\$C\$13)

becomes

({2; 6; 4; 5; 3; 9; 3; 2; 0; 1}< =3)*({2; 6; 4; 5; 3; 9; 3; 2; 0; 1}> =0)

becomes

{TRUE; FALSE; FALSE; FALSE; TRUE; FALSE; TRUE; TRUE; TRUE; TRUE}*{TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE}

Both conditions must be met, the asterisk lets us multiple the arrays meaning AND logic.

TRUE * TRUE equals FALSE, all other combinations return False. TRUE * FALSE equals FALSE and so on.

{TRUE; FALSE; FALSE; FALSE; TRUE; FALSE; TRUE; TRUE; TRUE; TRUE} * {TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE}

returns

{1; 0; 0; 0; 1; 0; 1; 1; 1; 1}.

Boolean values have numerical equivalents, TRUE = 1 and FALSE equals 0 (zero). They are converted when you perform an arithmetic operation in a formula.

#### Step 4 - Create number sequence

The ROW function calculates the row number of a cell reference.

ROW(reference)

ROW(\$B\$3:\$E\$12)

returns

{3; 4; 5; 6; 7; 8; 9; 10; 11; 12}.

#### Step 5 - Create a number sequence from 1 to n

The MATCH function returns the relative position of an item in an array or cell reference that matches a specified value in a specific order.

MATCH(ROW(\$B\$3:\$E\$12), ROW(\$B\$3:\$E\$12))

becomes

MATCH({3; 4; 5; 6; 7; 8; 9; 10; 11; 12}, {3; 4; 5; 6; 7; 8; 9; 10; 11; 12})

and returns

{1; 2; 3; 4; 5; 6; 7; 8; 9; 10}.

#### Step 6 - Return the corresponding row number

The IF function returns one value if the logical test is TRUE and another value if the logical test is FALSE.

IF(logical_test, [value_if_true], [value_if_false])

IF((INDEX(\$B\$3:\$E\$12, , \$D\$16)< =\$D\$15)*(INDEX(\$B\$3:\$E\$12, , \$D\$16)> =\$D\$14), MATCH(ROW(\$B\$3:\$E\$12), ROW(\$B\$3:\$E\$12)), "")

becomes

IF({1; 0; 0; 0; 1; 0; 1; 1; 1; 1}, MATCH(ROW(\$B\$3:\$E\$12), ROW(\$B\$3:\$E\$12)), "")

becomes

IF({1; 0; 0; 0; 1; 0; 1; 1; 1; 1}, {1; 2; 3; 4; 5; 6; 7; 8; 9; 10}, "")

and returns

{1; ""; ""; ""; 5; ""; 7; 8; 9; 10}.

#### Step 7 - Extract k-th smallest row number

The SMALL function returns the k-th smallest value from a group of numbers.

SMALL(arrayk)

SMALL(IF((INDEX(\$B\$3:\$E\$12, , \$D\$16)< =\$D\$15)*(INDEX(\$B\$3:\$E\$12, , \$D\$16)> =\$D\$14), MATCH(ROW(\$B\$3:\$E\$12), ROW(\$B\$3:\$E\$12)), ""), ROWS(B20:\$B\$20))

becomes

SMALL({1; ""; ""; ""; 5; ""; 7; 8; 9; 10}, ROWS(B20:\$B\$20))

becomes

SMALL({1; ""; ""; ""; 5; ""; 7; 8; 9; 10}, 1)

and returns 1.

#### Step 8 - Return the entire row record from the cell range

The INDEX function returns a value from a cell range, you specify which value based on a row and column number.

INDEX(array[row_num][column_num])

INDEX(\$B\$3:\$E\$12, SMALL(IF((INDEX(\$B\$3:\$E\$12, , \$D\$16)< =\$D\$15)*(INDEX(\$B\$3:\$E\$12, , \$D\$16)> =\$D\$14), MATCH(ROW(\$B\$3:\$E\$12), ROW(\$B\$3:\$E\$12)), ""), ROWS(B20:\$B\$20)), COLUMNS(\$A\$1:A1))

becomes

INDEX(\$B\$3:\$E\$12, 1, , 1)

and returns {2, "Ken Smith", 6, "North"}.

Recommended articles

Match two criteria and return multiple records
This article demonstrates how to extract records/rows based on two conditions applied to two different columns, you can easily extend […]
Extract records where all criteria match if not empty
Question: I second G's question: can this be done for more than 3? i.e. (Instead of last name, middle, first) […]
Extract all rows that contain a value between this and that
Question: I have a list and I want to filter out all rows that have a value (Column C) that […]
Extract records between two dates
This article presents methods for filtering rows in a dataset based on a start and end date. The image above […]
Filter records based on a date range and a text string
Murlidhar asks: How do I search text in cell and use a date range to filter records? i.e st.Dt D1 […]
Search for a text string in a data set and return multiple records
This article explains different techniques that filter rows/records that contain a given text string in any of the cell values […]
Extract records containing negative numbers
How to extract rows containing digits [Formula]
This article describes a formula that returns all rows containing at least one digit 0 (zero) to 9. What's on […]

## 2. Extract all rows from a range based on range criteria - Excel 365 Update 17 December 2020, the new FILTER function is now available for Excel 365 users.

Excel 365 dynamic array formula in cell B20:

=FILTER(\$B\$3:\$E\$12, (D3:D12<=D15)*(D3:D12>=D14))

It is a regular formula, however, it returns an array of values and extends automatically to cells below and to the right. Microsoft calls this a dynamic array and spilled array.

The array formula below is for earlier Excel versions, it searches for values that meet a range criterion (cell D14 and D15), the formula lets you change the column to search in with cell D16.

This formula can be used with whatever dataset size and shape. To search the first column, type 1 in cell D16. This is a great improvement in both formula size and how easy it is to enter the formula, compared to the array formula in section 1.

### 2.1 Explaining array formula

#### Step 1 - First condition

The less than character and the equal sign are both logical operators meaning they are able to compare value to value, the output is a boolean value.

In this case, the logical expression evaluates if numbers in D3:D12 are smaller than or equal to the condition specified in cell D15.

D3:D12<=D15

becomes

{2;6;4;5;3;9;3;2;0;1}<=6

and returns

{TRUE; TRUE; TRUE; TRUE; TRUE; FALSE; TRUE; TRUE; TRUE; TRUE}.

#### Step 2 - Second condition

The second condition checks if the number in D3:D12 are larger than or equal to the condition specified in cell D14.

D3:D12>=D14

becomes

{2;6;4;5;3;9;3;2;0;1}>=4

and returns

{FALSE; TRUE; TRUE; TRUE; FALSE; TRUE; FALSE; FALSE; FALSE; FALSE}.

#### Step 3 - Multiply arrays - AND logic

The asterisk lets you multiply a number to a number, in this case, array to array. Both arrays must be of the exact same size.

The parentheses let you control the order of operation, we want to evaluate the comparisons first before we multiply the arrays.

(D3:D12<=D15)*(D3:D12>=D14)

becomes

{TRUE; TRUE; TRUE; TRUE; TRUE; FALSE; TRUE; TRUE; TRUE; TRUE}*{FALSE; TRUE; TRUE; TRUE; FALSE; TRUE; FALSE; FALSE; FALSE; FALSE}

and returns

{0; 1; 1; 1; 0; 0; 0; 0; 0; 0}.

AND logic works like this:

TRUE * TRUE = TRUE (1)
TRUE * FALSE = FALSE (0)
FALSE * TRUE = FALSE (0)
FALSE * FALSE = FALSE (0)

Note that multiplying boolean values returns their numerical equivalents.
TRUE = 1 and FALSE = 0 (zero).

#### Step 4 - Filter values based on the array

The FILTER function lets you extract values/rows based on a condition or criteria.
FILTER(arrayinclude, [if_empty])

FILTER(\$B\$3:\$E\$12, (D3:D12<=D15)*(D3:D12>=D14))

becomes

FILTER({1, "John Doe", 2, "North"; 2, "Ken Smith", 6, "North"; 3, "Abraham Johnson", 4, "South"; 4, "Don Williams", 5, "West"; 5, "Brenda Jones", 3, "South"; 6, "Kenneth Brown", 9, "East"; 7, "Jennifer Davis", 3, "West"; 8, "Brittany Miller", 2, "West"; 9, "Martin Wilson", 0, "South"; 10, "Roger Moore", 1, "East"}, (D3:D12<=D15)*(D3:D12>=D14))

becomes

FILTER({1, "John Doe", 2, "North"; 2, "Ken Smith", 6, "North"; 3, "Abraham Johnson", 4, "South"; 4, "Don Williams", 5, "West"; 5, "Brenda Jones", 3, "South"; 6, "Kenneth Brown", 9, "East"; 7, "Jennifer Davis", 3, "West"; 8, "Brittany Miller", 2, "West"; 9, "Martin Wilson", 0, "South"; 10, "Roger Moore", 1, "East"}, {0; 1; 1; 1; 0; 0; 0; 0; 0; 0})

and returns

{2, "Ken Smith", 6, "North"; 3, "Abraham Johnson", 4, "South"; 4, "Don Williams", 5, "West"}.

## 3. Extract all rows from a range that meet the criteria in one column [Array formula] The array formula in cell B20 extracts records where column E equals either "South" or "East". You can use as many conditions as you like as long as you adjust the cell reference \$E\$15:\$E\$16 accordingly in the formula below.

The following array formula in cell B20 is for earlier Excel versions than Excel 365:

=INDEX(\$B\$3:\$E\$12, SMALL(IF(COUNTIF(\$E\$15:\$E\$16,\$E\$3:\$E\$12), MATCH(ROW(\$B\$3:\$E\$12), ROW(\$B\$3:\$E\$12)), ""), ROWS(B20:\$B\$20)), COLUMNS(\$B\$2:B2))

To enter an array formula, type the formula in a cell then press and hold CTRL + SHIFT simultaneously, now press Enter once. Release all keys.

The formula bar now shows the formula with a beginning and ending curly bracket telling you that you entered the formula successfully. Don't enter the curly brackets yourself.

### 3.1 Explaining formula in cell B20

#### Step 1 - Filter a specific column in cell range \$A\$2:\$D\$11

The COUNTIF function allows you to identify cells in range \$E\$3:\$E\$12 that equals \$E\$15:\$E\$16.

COUNTIF(\$E\$15:\$E\$16,\$E\$3:\$E\$12)

becomes

COUNTIF({"South"; "East"},{"North"; "North"; "South"; "West"; "South"; "East"; "West"; "West"; "South"; "East"})

and returns

{0;0;1;0;1;1;0;0;1;1}.

#### Step 2 - Return corresponding row number

The IF function has three arguments, the first one must be a logical expression. If the expression evaluates to TRUE then one thing happens (argument 2) and if FALSE another thing happens (argument 3).

The logical expression was calculated in step 1 , TRUE equals 1 and FALSE equals 0 (zero).

IF(COUNTIF(\$E\$15:\$E\$16,\$E\$3:\$E\$12), MATCH(ROW(\$B\$3:\$E\$12), ROW(\$B\$3:\$E\$12)), "")

becomes

IF({0; 0; 1; 0; 1; 1; 0; 0; 1; 1}, MATCH(ROW(\$B\$3:\$E\$12), ROW(\$B\$3:\$E\$12)), "")

becomes

IF({0; 0; 1; 0; 1; 1; 0; 0; 1; 1}, {1; 2; 3; 4; 5; 6; 7; 8; 9; 10}, "")

and returns

{""; ""; 3; ""; 5; 6; ""; ""; 9; 10}.

#### Step 3 - Find k-th smallest row number

SMALL(IF(COUNTIF(\$E\$15:\$E\$16,\$E\$3:\$E\$12), MATCH(ROW(\$B\$3:\$E\$12), ROW(\$B\$3:\$E\$12)), ""), ROWS(B20:\$B\$20))

becomes

SMALL({""; ""; 3; ""; 5; 6; ""; ""; 9; 10}, ROWS(B20:\$B\$20))

becomes

SMALL({""; ""; 3; ""; 5; 6; ""; ""; 9; 10}, 1)

and returns 3.

#### Step 4 - Return value based on row and column number

The INDEX function returns a value based on a cell reference and column/row numbers.

INDEX(\$B\$3:\$E\$12, SMALL(IF(COUNTIF(\$E\$15:\$E\$16,\$E\$3:\$E\$12), MATCH(ROW(\$B\$3:\$E\$12), ROW(\$B\$3:\$E\$12)), ""), ROWS(B20:\$B\$20)), COLUMNS(\$B\$2:B2))

becomes

INDEX(\$B\$3:\$E\$12, 3, COLUMNS(\$B\$2:B2))

becomes

INDEX(\$B\$3:\$E\$12, 3, 1)

and returns 3 in cell B20.

Recommended articles

Match two criteria and return multiple records
This article demonstrates how to extract records/rows based on two conditions applied to two different columns, you can easily extend […]
Extract records where all criteria match if not empty
Question: I second G's question: can this be done for more than 3? i.e. (Instead of last name, middle, first) […]
Extract all rows that contain a value between this and that
Question: I have a list and I want to filter out all rows that have a value (Column C) that […]
Extract records between two dates
This article presents methods for filtering rows in a dataset based on a start and end date. The image above […]
Filter records based on a date range and a text string
Murlidhar asks: How do I search text in cell and use a date range to filter records? i.e st.Dt D1 […]
Search for a text string in a data set and return multiple records
This article explains different techniques that filter rows/records that contain a given text string in any of the cell values […]
Extract records containing negative numbers
How to extract rows containing digits [Formula]
This article describes a formula that returns all rows containing at least one digit 0 (zero) to 9. What's on […]

## 4. Extract all rows from a range based on multiple conditions - Excel 365 Update 17 December 2020, the new FILTER function is now available for Excel 365 users.

Excel 365 dynamic array formula in cell B20:

=FILTER(\$B\$3:\$E\$12, COUNTIF(E15:E16, E3:E12))

It is a regular formula, however, it returns an array of values. Read here how it works: Filter values based on criteria

The formula extends automatically to cells below and to the right. Microsoft calls this a dynamic array and spilled array.

### 4.1 Explaining array formula

#### Step 1 - Check if values equal criteria

The COUNTIF function calculates the number of cells that meet a given condition.
COUNTIF(rangecriteria)

COUNTIF(\$E\$15:\$E\$16,\$E\$3:\$E\$12)

becomes

COUNTIF({"South"; "East"},{"North"; "North"; "South"; "West"; "South"; "East"; "West"; "West"; "South"; "East"})

and returns

{0; 0; 1; 0; 1; 1; 0; 0; 1; 1}.

#### Step 2 - Filter records based on array

The FILTER function lets you extract values/rows based on a condition or criteria.
FILTER(arrayinclude, [if_empty])

FILTER(\$B\$3:\$E\$12, COUNTIF(E15:E16, E3:E12))

becomes

FILTER(\$B\$3:\$E\$12, {0; 0; 1; 0; 1; 1; 0; 0; 1; 1})

and returns

{3, "Abraham Johnson", 4, "South"; 5, "Brenda Jones", 3, "South"; 6, "Kenneth Brown", 9, "East"; 9, "Martin Wilson", 0, "South"; 10, "Roger Moore", 1, "East"}.

## 5. Extract all rows from a range that meet the criteria in one column [Excel defined Table] The image above shows a dataset converted to an Excel defined Table, a number filter has been applied to the third column in the table.

Here are the instructions to create an Excel Table and filter values in column 3.

1. Select a cell in the dataset.
2. Press CTRL + T 3. Press with left mouse button on check box "My table has headers".
4. Press with left mouse button on OK button. The image above shows the Excel defined Table, here is how to filter D between 4 and 6:

1. Press with left mouse button on black arrow next to header.
2. Press with left mouse button on "Number Filters".
3. Press with left mouse button on "Between...". 4. Type 4 and 6. 5. Press with left mouse button on OK button. ## 6. Extract all rows from a range that meet the criteria in one column [AutoFilter] The image above shows filtered records based on two conditions, values in column D are larger or equal to 4 or smaller or equal to 6.

Here is how to apply Filter arrows to a dataset.

1. Select any cell within the dataset range.
2. Go to tab "Data" on the ribbon.
3. Press with left mouse button on "Filter button". Black arrows appear next to each header. Lets filter records based on conditions applied to column D.

1. Press with left mouse button on the black arrow next to the header in Column D, see the image below.
2. Press with left mouse button on "Number Filters".
3. Press with left mouse button on "Between". 4. Type 4 and 6 in the dialog box shown below. 5. Press with left mouse button on OK button.

## 7. Extract all rows from a range that meet the criteria in one column [Advanced Filter] The image above shows a filtered dataset in cell range B5:E15 using Advanced Filter which is a powerful feature in Excel.

Here is how to apply a filter:

1. Create headers for the column you want to filter, preferably above or below your data set.
Your filters will possibly disappear if placed next to the data set because rows may become hidden when the filter is applied.
2. Select the entire dataset including headers.
3. Go to tab "Data" on the ribbon.
4. Press with left mouse button on the "Advanced" button. 5. A dialog box appears. 6. Select the criteria range C2:D3, shown ithe n above image.
7. Press with left mouse button on OK button. Recommended articles

Extract duplicate records
This article describes how to filter duplicate rows with the use of a formula.  It is, in fact, an array […]
Filter unique distinct records
Table of contents Filter unique distinct row records Filter unique distinct row records but not blanks Filter unique distinct row […] 