## Explanation

In this example, the goal is to extract the last name from a list of names in "Last, First" format as seen in column B. In the current version of Excel, the easiest solution is to use the TEXTBEFORE function. In older versions of Excel, it can be solved with a more complex formula based on the LEFT and FIND functions. Both approaches are explained below.

### Modern solution

In the current version of Excel, the TEXTBEFORE function is the best way to solve this problem. TEXTBEFORE extracts text that occurs *before* a given delimiter. In its simplest form, TEXTBEFORE only requires two arguments, *text* and *delimiter*:

`=TEXTBEFORE(text,delimiter)`

In the worksheet shown, the formula we are using to return the last name looks like this:

`=TEXTBEFORE(B5,",")`

*text*- B5, the name in column B*delimiter*- "," (a comma)

Note that the comma needs to be enclosed in double quotes (",") and there is no need to add a space after the comma. In this configuration, the TEXTBEFORE function simply returns all text that occurs *before* the comma. TEXTBEFORE has many other options that you can read more about here.

### Legacy solution

In older versions of Excel that do not provide the TEXTBEFORE function, you can solve this problem with a more complex formula based on the RIGHT, LEN, and FIND functions:

`=LEFT(B5,FIND(",",B5)-1)`

At a high level, the LEFT function extracts text starting at the *left* side of a text string. LEFT takes two arguments, *text* and *num_chars*, which indicates how many characters to extract:

```
=LEFT(text,num_chars)
```

For example, if we use "apple" for *text* and 3 for *num_chars*, we get "app":

```
=LEFT("apple",3) returns "app"
```

The main challenge in this example is to calculate how many characters to extract, which is equal to the length of the last name. This is done with the FIND function like this:

`FIND(",",B5)-1`

FIND returns the location of text as a numeric position. Because the comma appears as the 6th character in the text, the FIND function returns 6. This is one more character than we need, so we subtract 1:

```
FIND(",",B5)-1 // returns 5
```

The result is 5, which is the length of the last name in "Chang, Amy". The code above returns this result directly to the LEFT function as the *num_chars* argument:

```
LEFT("Chang, Amy",5) // returns "Chang"
```

LEFT returns "Chang" as the final result. To extract the *first* name from names in column B see the formulas on this page.