## Extract unique distinct values from cell range that begins with string

The array formula in cell B10 extracts unique distinct values from cell range B2:D4 that begins with a given condition specified in cell C7.

Array formula in B10:

Copy cell B10 and paste it down as far as needed.

### Explaining formula in cell B10

#### Step 1 - Identify values beginning with search string

The LEFT function returns a given number of characters from the start of a text string.

LEFT($B$2:$D$4, LEN($C$7))=$C$7

becomes

LEFT({"Apple", "Banana", "Blackberry";"Orange", "Lemon", "Blood orange";"Blueberry", "Banana", "Orange"}, LEN($C$7))=$C$7

becomes

LEFT({"Apple", "Banana", "Blackberry";"Orange", "Lemon", "Blood orange";"Blueberry", "Banana", "Orange"}, 2)=$C$7

becomes

{"Ap","Ba","Bl"; "Or","Le","Bl"; "Bl","Ba","Or"}=$C$7

becomes

{"Ap","Ba","Bl"; "Or","Le","Bl"; "Bl","Ba","Or"}="Bl"

and returns

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

#### Step 2 - Keep track of previous values

TheÂ COUNTIF functionÂ counts values based on a condition or criteria, the first argument contains an expanding cell reference, it grows when the cell is copied to cells below. This makes the formula aware of values displayed in cells above.

COUNTIF(B9:$B$9, $B$2:$D$4)=0

becomes

COUNTIF("Text", {"Apple", "Banana", "Blackberry";"Orange", "Lemon", "Blood orange";"Blueberry", "Banana", "Orange"})=0

becomes

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

and returns

{TRUE,TRUE,TRUE; TRUE,TRUE,TRUE; TRUE,TRUE,TRUE}.

#### Step 3 - Multiply arrays

Both values must be true in order to get the value in a later step.

(LEFT($B$2:$D$4, LEN($C$7))=$C$7)*(COUNTIF(B9:$B$9, $B$2:$D$4)=0)

becomes

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

and returns

{0,0,1; 0,0,1; 1,0,0}

#### Step 4 - Replace TRUE with unique number

TheÂ IF functionÂ returns a unique number if boolean value is TRUE. FALSE returns "" (nothing). The unique number is needed to find the right value in a later step.

IF((LEFT($B$2:$D$4, LEN($C$7))=$C$7)*(COUNTIF(B9:$B$9, $B$2:$D$4)=0), (ROW($B$2:$D$4)+(1/(COLUMN($B$2:$D$4)+1)))*1, "")

becomes

IF({0,0,1; 0,0,1; 1,0,0}, (ROW($B$2:$D$4)+(1/(COLUMN($B$2:$D$4)+1)))*1, "")

becomes

IF({0,0,1; 0,0,1; 1,0,0}, {2.33333333333333, 2.25, 2.2; 3.33333333333333, 3.25, 3.2; 4.33333333333333, 4.25, 4.2}, "")

and returns

{"","",2.2;"","",3.2;4.33333333333333,"",""}

#### Step 5 - Find smallest value in array

TheÂ MIN functionÂ returns the smallest number in array ignoring blanks and text values.

MIN(IF((LEFT($B$2:$D$4,LEN($C$7))=$C$7)*(COUNTIF(B9:$B$9, $B$2:$D$4)=0), (ROW($B$2:$D$4)+(1/(COLUMN($B$2:$D$4)+1)))*1, ""))

becomes

MIN({"","",2.2;"","",3.2;4.33333333333333,"",""})

and returnsÂ 2.2.

#### Step 6 - Find corresponding value

IF(MIN(IF((LEFT($B$2:$D$4, LEN($C$7))=$C$7)*(COUNTIF(B9:$B$9, $B$2:$D$4)=0), (ROW($B$2:$D$4)+(1/(COLUMN($B$2:$D$4)+1)))*1, ""))=(ROW($B$2:$D$4)+(1/(COLUMN($B$2:$D$4)+1)))*1, $B$2:$D$4, "")

becomes

IF(2.2={2.33333333333333, 2.25, 2.2; 3.33333333333333, 3.25, 3.2; 4.33333333333333, 4.25, 4.2}, $B$2:$D$4, "")

becomes

IF({FALSE,FALSE,TRUE;FALSE,FALSE,FALSE;FALSE,FALSE,FALSE}, $B$2:$D$4, "")

and returns

{"","","Blackberry";"","","";"","",""}

#### Step 7 - Concatenate strings in array

TheÂ TEXTJOIN functionÂ returns values concatenated ignoring blanks in array.

TEXTJOIN("", TRUE, IF(MIN(IF((LEFT($B$2:$D$4, LEN($C$7))=$C$7)*(COUNTIF(B9:$B$9, $B$2:$D$4)=0), (ROW($B$2:$D$4)+(1/(COLUMN($B$2:$D$4)+1)))*1, ""))=(ROW($B$2:$D$4)+(1/(COLUMN($B$2:$D$4)+1)))*1, $B$2:$D$4, ""))

becomes

TEXTJOIN("", TRUE, {"","","Blackberry";"","","";"","",""})

and returns "Blackberry" in cell B10.

### Get Excel *.xlsx file

Extract unique distinct values begins with A in a range using array formula in excel.xlsx

### 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. […]

### Functions in this article

More than 1300 Excel formulas

## Excel categories

### 3 Responses to “Extract unique distinct values from cell range that begins with 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

Oscar,

Your code has aided me tremendously; THANK YOU!! I have the existing criterion based, unique distinct list formula

I am trying to add "begins with" criteria to rngITEMDescr, such that any item that begins with "PLATE" is excluded from the unique distinct list.

Randy

Randy Braddock

Thank you.

I have added content to this post:

https://www.get-digital-help.com/automatically-filter-unique-row-records-from-multiple-columns/#notbegin

I believe it has the answer to your question.

This article is most helpful. Is it possible to put more than one value in cell C7? I am trying to extract values that begin with two different strings. Thank-you.