Count words in a cell 

How can we count the num­ber of words in a cell?

Count words in a cell 

We can count the num­ber of spaces between words. Let’s have a look at our first exam­ple. In cell A2, we have spaces between words and at the end of each line, so the case is sim­ple. We can use the LEN func­tion here that counts the length of text (Fig. 1).

=LEN(A2)

LEN function
Fig. 1 LEN function

Now, that we have the num­ber of signs, we can remove spaces. We can use the SUBSTITUTE func­tion here. This func­tion will change the old text, which in our case is a space into new text. And since we want to remove spaces, our new text will be an emp­ty text string writ­ten in dou­ble quotes (Fig. 2). 

=SUBSTITUTE(A2,” “,“”)

Fig. 2 SUBSTITUTE function

We can see that the func­tion removed all spaces from our text (Fig. 3). 

No spaces
Fig. 3 No spaces

Now, we can count the length of the text with­out spaces using the LEN func­tion (Fig.4).

=LEN(SUBSTITUTE(A2,” “,“”)

Counting the text length
Fig. 4 Count­ing the text length

Now we know the length (Fig. 5).

Text length
Fig. 5 Text length

Since we know how many spaces there are, we can use the for­mu­la to count the words. We just have to sub­tract this for­mu­la from the pre­vi­ous one (Fig. 6). 

=LEN(A2)-LEN(SUBSTITUTE(A2,” “,“”))

 Subtracting formulas
Fig. 6 Sub­tract­ing formulas

And we have the num­ber of spaces (Fig. 7).

Number of spaces
Fig. 7 Num­ber of spaces

We still have to remem­ber that to count the num­ber of words, we have to add 1 because there is only one space between two words (Fig. 8).

=LEN(A2)-LEN(SUBSTITUTE(A2,” “,“”))+1

One space between two words
Fig. 8 One space between two words

Now we know the num­ber of words in each cell. 

Number of words
Fig. 9 Num­ber of words

If we want to count words from all cells, we can use almost the same for­mu­la. The only thing we have to change is the range which now will be from A2 to A4 (Fig. 10). 

=LEN(A2:A4)-LEN(SUBSTITUTE(A2:A4,” “,“”))+1

Adding a new range
Fig. 10 Adding a new range

In Dynam­ic Array Excel, the results will be spilled, how­ev­er we can sum the up (Fig. 11).

Split results
Fig. 11 Split results

In the pre­vi­ous ver­sion of Excel we can use the the SUMPRODUCT func­tion (Fig. 12). 

=SUMPRODUCT(LEN(A2:A4)-LEN(SUBSTITUTE(A2:A4,” “,“”))+1

 SUMPRODUCT function
Fig. 12 SUMPRODUCT function

Final results (Fig. 13).

Final result
Fig. 13 Final result

https://www.youtube.com/watch?v=ywuJZ8u_hDA

Extract First Last and Middle Name with Formulas 

Today, we are going to talk about extract­ing first names, mid­dle names and last names from full names. We define the first name as the first word from the left, the last name as the first word from the right, and the mid­dle name, as every­thing between those two. Mid­dle names are a bit com­pli­cat­ed, as they can may con­sist of one word, a space, an abbre­vi­a­tion, or two or more words (Fig. 1)

Extract First Last and Mid­dle Name with Formulas
A list of names
Fig. 1 A list of names

Let’s start with extract­ing the first name. We just have to use the LEFT func­tion, which extracts signs from the left. We have to insert the FIND func­tion there, so that it finds the first space, and write the space in dou­ble quotes (Fig. 2)

=LEFT(A2,FIND(“ “,A2))

Extracting the first name
Fig. 2 Extract­ing the first name

Now, we have the first name (Fig. 3).

The first name
Fig. 3 The first name

But, we have to remem­ber that the FIND func­tion will return the posi­tion of the sign we’re look­ing for, which means that it finds the 7th posi­tion, which is a space (Fig. 4). 

7th position
Fig. 4 7th position

The first name , how­ev­er, con­sists of only 6 let­ters, which is what we want. It means that we want to extract less let­ters. So, we have write the for­mu­la once again, but this time we sub­tract one sign (Fig. 5)

=LEFT(A2,FIND(“ “,A2)-1)

Subtracting one sign
Fig. 5 Sub­tract­ing one sign

Now, we have only the first name with­out unnec­es­sary signs. After drag­ging it down, the whole col­umn is full (Fig. 6)

Full column
Fig. 6 Full column

Let’s go to last names. This case is a bit more com­pli­cat­ed. We don’t know whether we’re look­ing for the first, the sec­ond, the third or even a more dis­tant space (Fig. 7) 

Too many possible spaces
Fig. 7 Too many pos­si­ble spaces

There’s a trick to solve it. We have to repeat spaces. With­in our text, we have to sub­sti­tute a sin­gle space into many spaces, let’s say 29. We use the REPT func­tion (Fig. 8)

=SUBSTITUTE(A2,” “,REPT(“ “,29))

Repeating spaces
Fig. 8 Repeat­ing spaces

After accept­ing our func­tion, we have our changed names with many spaces between them (Fig. 9)

Names with many spaces
Fig. 9 Names with many spaces

Now, we can start extract­ing names from the right side. We’re extract­ing not only all signs from our name, but also the remain­ing 29 signs (Fig. 10).

=RIGHT(SUBSTITUTE(A2,” “,REPT(“ “,29)),29)

Extracting name and 29 signs
Fig. 10 Extract­ing name and 29 signs

Now, we have the last name and many, many spaces before it (Fig. 11)

Name with spaces
Fig. 11 Name with spaces

We have to delete them using the TRIM func­tion. The TRIM func­tion removes all spaces from a text string except for a sin­gle space between words. So, each space at the begin­ning and at the end of the string will be removed (Fig. 12)

=TRIM(RIGHT(SUBSTITUTE(A2,” “,REPT(“ “,29)),29))

Trimming unnecessary spaces
Fig. 12 Trim­ming unnec­es­sary spaces

After accept­ing it and copy­ing it down, we have our last names (Fig. 13). 

Last names
Fig. 13 Last names

Now, we have to find the thing between the first and the last name. We will use the SUBSTITUTE func­tion. In the place of the first name, we will place noth­ing, i.e. an emp­ty text string (Fig. 14). 

=SUBSTITUTE(A2,B2,“”)

Finding the middle name
Fig. 14 Find­ing the mid­dle name

Now, we have a short­er ver­sion of our name (Fig. 15).

Shorter version
Fig. 15 Short­er version

Let’s remove the last name now. We want to sub­sti­tute the last name with an emp­ty text string (Fig. 16)

=SUBSTITUTE(SUBSTITUTE(A2,B2,“”),D2,“”)

Removing the last name
Fig. 16 Remov­ing the last name

After enter­ing and copy­ing down, we have every­thing between the first name and the last name (Fig. 17). As you can see, we have also extract­ed spaces which we don’t need. So, let’s use the TRIM func­tion to delete unnec­es­sary spaces.

=TRIM(SUBSTITUTE(SUBSTITUTE(A2,B2,“”),D2,“”))

Unneeded spaces
Fig. 17 Unneed­ed spaces

Because we are edit­ing whole col­umn we can press Ctrl + Enter.

That’s how we extract first names, last names and every­thing in between with appro­pri­ate formulas. 

Final results
Fig. 18 Final results

https://www.youtube.com/watch?v=v46vQGjwx0w