## Extract unique distinct values if value contains string

The image above demonstrates a formula in cell F3 that extracts unique distinct values from column B if they contain the value in cell D3.

Formula in cell F3:

### Explaining formula in cell F3

#### Step 1 - Prevent duplicates

The COUNTIF function counts cells in cell range based on a condition or criteria. If the value is equal to 0 then it has not been displayed yet.

COUNTIF($F$2:F2, $B$3:$B$21)=0

becomes

COUNTIF("Search results "contain" search value

Unique distinct list", {"Federer, Roger "; "Djokovic, Novak "; "Murray, Andy "; "Davydenko, Nikolay "; "Roddick, Andy "; "Del Potro, Juan Martin "; "Federer, Roger "; "Davydenko, Nikolay "; "Verdasco, Fernando "; "Gonzalez, Fernando "; "Wawrinka, Stanislas "; "Gonzalez, Fernando "; "Blake, James "; "Nalbandian, David "; "Robredo, Tommy "; "Wawrinka, Stanislas "; "Cilic, Marin "; "Stepanek, Radek "; "Almagro, Nicolas "})=0

becomes

{0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0}=0

and returns

{TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE}

#### Step 2 - Check if values contain string

The SEARCH function returns a number that represents the position of the search string if found. The function returns an error if not found which is alright in this case.

SEARCH($D$3,$B$3:$B$21)

becomes

SEARCH("r",$B$3:$B$21)

and returns

{5; #VALUE!; 3; #VALUE!; 1; 8; 5; #VALUE!; 3; 13; 4; 13; #VALUE!; #VALUE!; 1; 4; 10; 11; 6}.

#### Step 3 - Multiply arrays

Both values must be TRUE in order to be TRUE meaning if the value has not been displayed yet AND the value contains the string then return TRUE or the equivalent numerical number. TRUE is all numbers except 0 (zero), FALSE is 0 (zero).

{TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE; TRUE}* {5; #VALUE!; 3; #VALUE!; 1; 8; 5; #VALUE!; 3; 13; 4; 13; #VALUE!; #VALUE!; 1; 4; 10; 11; 6}

and returns

{5; #VALUE!; 3; #VALUE!; 1; 8; 5; #VALUE!; 3; 13; 4; 13; #VALUE!; #VALUE!; 1; 4; 10; 11; 6}.

#### Step 4 - Divide 1 with array

The result will return !DIV/0 error if 1 is divided with 0 (0), which the LOOKUP function ignores. It will also ignore #VALUE! errors.

1/((COUNTIF($F$2:F2, $B$3:$B$21)=0)*SEARCH($D$3, $B$3:$B$21))

becomes

1/{5; #VALUE!; 3; #VALUE!; 1; 8; 5; #VALUE!; 3; 13; 4; 13; #VALUE!; #VALUE!; 1; 4; 10; 11; 6}

and returns

{0.2; #VALUE!; 0.333333333333333; #VALUE!; 1; 0.125; 0.2; #VALUE!; 0.333333333333333; 0.0769230769230769; 0.25; 0.0769230769230769; #VALUE!; #VALUE!; 1; 0.25; 0.1; 0.0909090909090909; 0.166666666666667}.

#### Step 5 - Return value

LOOKUP(2,1/((COUNTIF($F$2:F2,$B$3:$B$21)=0)*SEARCH($D$3,$B$3:$B$21)),$B$3:$B$21)

becomes

LOOKUP(2,{0.2; #VALUE!; 0.333333333333333; #VALUE!; 1; 0.125; 0.2; #VALUE!; 0.333333333333333; 0.0769230769230769; 0.25; 0.0769230769230769; #VALUE!; #VALUE!; 1; 0.25; 0.1; 0.0909090909090909; 0.166666666666667},$B$3:$B$21)

becomes

LOOKUP(2,{0.2; #VALUE!; 0.333333333333333; #VALUE!; 1; 0.125; 0.2; #VALUE!; 0.333333333333333; 0.0769230769230769; 0.25; 0.0769230769230769; #VALUE!; #VALUE!; 1; 0.25; 0.1; 0.0909090909090909; 0.166666666666667}, {"Federer, Roger "; "Djokovic, Novak "; "Murray, Andy "; "Davydenko, Nikolay "; "Roddick, Andy "; "Del Potro, Juan Martin "; "Federer, Roger "; "Davydenko, Nikolay "; "Verdasco, Fernando "; "Gonzalez, Fernando "; "Wawrinka, Stanislas "; "Gonzalez, Fernando "; "Blake, James "; "Nalbandian, David "; "Robredo, Tommy "; "Wawrinka, Stanislas "; "Cilic, Marin "; "Stepanek, Radek "; "Almagro, Nicolas "})

and returns

"Almagro, Nicolas " in cell F3.

### Get Excel *.xlsx file

### Advanced filter excel category

First, let me explain the difference between unique values and unique distinct values, it is important you know the difference […]

Question: hi all, thanks for the great formula/array formula. it works great. lately, i noticed that the array formula will […]

Question: How do I filter the last xx years or xx months in Excel? How do I exclude the current […]

This article demonstrates a formula that allows you to search a data set using any number of conditions, however, one […]

Table of Contents How to filter using OR logic between columns Advanced custom date filter 1. How to filter using […]

I highly recommend you keep the original data and only copy the data excluding blank rows and paste to a […]

### Unique distinct values category

First, let me explain the difference between unique values and unique distinct values, it is important you know the difference […]

Question: I have two ranges or lists (List1 and List2) from where I would like to extract a unique distinct […]

This article shows how to extract unique distinct values based on a condition applied to an adjacent column using formulas. […]

The array formula in cell D3 extracts unique distinct values sorted A to Z, from column B to column D. […]

Anura asks: Is it possible to extend this by matching items that meet a criteria? I have a list of […]

Question: How do I extract a unique distinct list from three ranges or lists? The ranges are not necessarily adjacent […]

This article demonstrates formulas that extract unique distinct values and ignore blank empty cells. Table of contents Extract a unique […]

Question: I have cell values spanning over several columns and I want to create a unique list from that range. […]

Question: How do I create a unique distinct list where other columns meet two criteria using excel array formula? Answer: […]

This article demonstrates formulas that extract sorted unique distinct values from a cell range containing also blanks. Unique distinct values […]

This article demonstrates two formulas that extract distinct values from a filtered Excel Table, one formula for Excel 365 subscribers […]

Question: How do I create a unique distinct list where adjacent cell values contain a search string? AA102 CA AA103 […]

EEK asks: I am looking for the same formula on this page, but targeting a range of MxN (spanning multiple […]

Filtering unique distinct text values and sort them based on the sum of adjacent values can easily be done by […]

This article demonstrates a formula that extracts unique distinct records/rows for a given month specified in cell C2, see the […]

Question: How do I create a unique distinct list from a column sorted A to Z using array formula? Array […]

Question: How to create unique distinct year and months from a long date listing (column A)? You can find the […]

Table of Contents Filter unique distinct values based on a date range How to enter an array formula Filter unique […]

Question: I want a unique distinct list to be created from a column where an adjacent column has text cell […]

## Functions in this article

More than 1300 Excel formulas

## Excel formula categories

## Excel categories

### 6 Responses to “Extract unique distinct values if value contains string”

### Leave a Reply

### How to comment

**How to add a formula to your comment**

<code>Insert your formula here.</code>

**Convert less than and larger than signs**

Use html character entities instead of less than and larger than signs.

< becomes < and > becomes >

**How to add VBA code to your comment**

[vb 1="vbnet" language=","]

Put your VBA code here.

[/vb]

**How to add a picture to your comment:**

Upload picture to postimage.org or imgur

Paste image link to your comment.

**Contact Oscar**

You can contact me through this contact form

I have a data in same way only difference is that they are in number format i.e. (330-1541) in this way so is there any way i can use the filter for such type of data. Please help me.

Ashok,

did you create an array formula?

[...] For Extracting Records From Data Set (12 Examples) - YouTube Bill Jelen - YouTube Or here... Filter unique distinct values using “contain” condition of a column in excel | Get Digit... I hope this helps. [...]

Do you have examples for using advanced filter for "Not Contains"?

I have a data of this sort...

Probe ID Call ID

USBE1 130226200131-1

USBE1 130226200131-2

USBE1 130226200131-3

USBE1 130226200131-4

USBE1 130226200521-1

USBE1R1 130227143154-1

USBE1R1 130227143154-10

USBE1R1 130227143154-11

USBE1R1 130227143154-12

USBE1R1 130227143154-13

USBE1R1 130227143154-14

USBE1R1 130227143154-15

..The "" condition works on the first column, but not on the second column..I am treating both as text columns. But the advanced filter for "Not" condition on these are not working..any help?

dashil103,

Sorry I don´t understand. What is the desired output?

I would like to do something vaguely similar to this. I would like to filter a list with tho columns. In the first column is an ID ("List 1", "List 2", "List 3", and so on), in the second one is a value. Now i would like to list all the values where the first row contains "List 1". Could you help me with this?