Author: Oscar Cronquist Article last updated on October 10, 2018

 

Question: How to extract email addresses from this sheet? (See pic below)

Answer:

It depends on how the emails are populated in your worksheet?

  • Are they in a single cell each?
  • Are there other text strings in the cell as well?

Example 1,

The following formula works if a cell contains only an email address, see image above. The TEXTJOIN function extracts all emails based on if character @ is found in the cell.

Array formula in cell C8:

=TEXTJOIN(", ", TRUE, IF(ISERROR(SEARCH("@", B2:E6)), "", B2:E6))

Example 2,

The example above has multiple text strings in each cell separated by a blank, the formula is only capable of extracting one email address per cell and if the delimiting character is a blank (space). You can change the formula to use any delimiting character, however, only one delimiting character per formula.

Formula in cell C3:

=TRIM(MID(SUBSTITUTE(TRIM(B3), " ", REPT(" ", 200)), (LEN(LEFT(B3, SEARCH("@", B3)))-LEN(SUBSTITUTE(LEFT(B3, SEARCH("@", B3))," ", "")))*200+1, 200))

Example 3,

It is possible to combine the array formulas in example 1 and 2, unfortunately, the formula can still only extract one email address per cell.

Array formula in cell B6:

=TEXTJOIN(CHAR(10), TRUE, IF(ISERROR(SEARCH("@", B2:D4)), "", TRIM(MID(SUBSTITUTE(TRIM(B2:D4), " ", REPT(" ", 200)), (LEN(LEFT(B2:D4, SEARCH("@", B2:D4)))-LEN(SUBSTITUTE(LEFT(B2:D4, SEARCH("@", B2:D4)), " ", "")))*200+1, 200))))

Cell B6 has "Wrap text" enabled, select cell B6 and press CTRL + 1 to open the "Format Cells" dialog box.

Example 4,

If you need an even better faster formula I recommend using a UDF:

Filter emails from an excel range [UDF]

This udf extracts all words containing a specified string. Example, Cell range B1:M50 contains random sentences. I have inserted some […]

Example 5,

The formula in cell F3 gets only one email address per row so it is very basic, however, check out the comments for more advanced formulas.

If the cell contains an email address and also other text strings it won't extract the email only, as I said, it is a very basic formula.

Array formula in F3:

=INDEX(B3:D3, 1, MIN(IF(ISERROR(SEARCH("@", B3:D3)), "", MATCH(COLUMN(B3:D3), COLUMN(B3:D3)))))

To enter an array formula, type the formula in cell F3 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, they appear automatically.

This article demonstrates how to filter emails with a custom function:

Filter emails from an excel range [UDF]

This udf extracts all words containing a specified string. Example, Cell range B1:M50 contains random sentences. I have inserted some […]

Explaining formula in cell F3

Step 1 - Look for @ character in cell range

The SEARCH function allows you to find the character position of a substring in a text string, we are, however, not interested in the position only if it exists or not in the cell.

SEARCH("@", B3:D3))

becomes

SEARCH("@", {"BB","john@doe.com","CC"}))

and returns {#VALUE!,5,#VALUE!}. This tells us that the second value in the array contains a @ character on position 5.

Step 2 - Convert array to TRUE or FALSE

The IF function can't handle error values in the logical expression so we must first convert the array to boolean values. The ISERROR function returns TRUE if the value is an error value and FALSE if not.

ISERROR(SEARCH("@", B3:D3))

becomes

ISERROR({#VALUE!,5,#VALUE!})

and returns {TRUE,FALSE,TRUE}.

Step 3 - Return column number if value is not an error value

IF(ISERROR(SEARCH("@", B3:D3)), "", MATCH(COLUMN(B3:D3), COLUMN(B3:D3)))

becomes

IF({TRUE,FALSE,TRUE}, "", MATCH(COLUMN(B3:D3), COLUMN(B3:D3)))

To create an array from 1 to n I use the MATCH function and COLUMN function.

IF({TRUE,FALSE,TRUE}, "", MATCH(COLUMN(B3:D3), COLUMN(B3:D3)))

becomes

IF({TRUE,FALSE,TRUE}, "", MATCH({2,3,4}, {2,3,4}))

becomes

IF({TRUE,FALSE,TRUE}, "", {1, 2,3})

and returns {"", 2,""}

Step 4 - Return the smallest column number

The MIN function calculates the smallest number in cell range or array.

MIN(IF(ISERROR(SEARCH("@", B3:D3)), "", MATCH(COLUMN(B3:D3), COLUMN(B3:D3))))

becomes

MIN({"", 2,""})

and returns 2.

Step 4 - Return value corresponding to column number

The INDEX function returns a value based on a row and/or column number.

INDEX(B3:D3, MIN(IF(ISERROR(SEARCH("@", B3:D3)), "", MATCH(COLUMN(B3:D3), COLUMN(B3:D3)))))

becomes

INDEX(B3:D3, 2)

and returns "john@doe.com".

Download Excel *.xlsx file

extract_email_2.xlsx

Learn to use regular expressions and filter emails:

Extract cell references from a formula

I am trying to build a regular expression that matches cell references in a formula. A regular expression is a […]

Learn how to use the LIKE operator to filter emails:

Working with the LIKE OPERATOR

The LIKE operator allows you to match a string to a pattern in excel vba. The following characters are specifically […]