Remove unnecessary spaces — TRIM function

Today, we are going to remove unnec­es­sary spaces. Some­times, there’s a space at the begin­ning of text, some­times, there are more than one space between two words, and some­times, there are some spaces at the end. The last ones are the hard­est to notice (Fig. 1)

Remove unnec­es­sary spaces — TRIM function
Unnecessary spaces
Fig. 1 Unnec­es­sary spaces

The name in the first line, Brave Bran­don with a space at the end, is some­thing dif­fer­ent for Excel, than Brave Bran­don with­out a space. In such a case, we want to use the TRIM func­tion to remove the space (Fig. 2)

Trim function
Fig. 2 TRIM function

After copy­ing it down, we have our names with­out unnec­es­sary spaces (Fig. 3)

No unnecessary spaces
Fig. 3 No unnec­es­sary spaces

This sim­ple func­tion removes unnec­es­sary spaces from the begin­ning, the end, and the mid­dle of text beetween words only leaves one space. 

https://www.youtube.com/shorts/Pe8z-PthW6Q

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

Extract middle names with Flash Fill

Today, we are going to extract mid­dle names from full names. How­ev­er, not every­body has got a mid­dle name, so let’s start with the first and the last name. We can use here the Flash Fill option, which means that we just have to start writ­ing the first name, then anoth­er first name. After that, the Flash Fill com­mand does the work for us (Fig. 1).

Extract mid­dle names with Flash Fill
Using the Flash Fill option
Fig. 1 — Using the Flash Fill option

All we need to do is accept the results with Enter, and we have the first names (Fig. 2)

Entering the results
Fig. 2 — Enter­ing the results

We do the same with the last name, i.e., we start writ­ing the last name in the first cell, but this time we will force the Flash Fill option to work by press­ing the Ctrl + E key­board short­cut (Fig. 3).  This way, we have last names (Fig. 4)

 Flash Fill
Fig. 3 — Flash Fill
Flash Fill results
Fig. 4 — Flash Fill results

Now, the hard­est part – mid­dle names. We start writ­ing the mid­dle name in the first row, how­ev­er, we don’t have a mid­dle name in the sec­ond row. This time we’ll also use the Flash Fill option (Fig. 5)

Flash Fill for middle names
Fig. 5 — Flash Fill for mid­dle names

When all mid­dle names have been extract­ed, we can see an error. Edward isn’t a mid­dle name. We have to cor­rect the Flash Fill answer. We can do it, until the Flash Fill Options icon is show­ing up (Fig. 6).

Flash Fill icon
Fig. 6 — Flash Fill icon

We have to change the mid­dle name, which, in fact, isn’t a mid­dle name, for a dif­fer­ent mark, e.g. an excla­ma­tion mark. We sim­ply write the mark in the place of the error, press Enter, and the Flash Fill option will do its mag­ic again (Fig. 7) Excla­ma­tion marks are in the rows, where there aren’t mid­dle names.

 Exclamation marks
Fig. 7 — Excla­ma­tion marks

We can put almost any­thing in the place of the excla­ma­tion mark, e.g. a star (Fig. 8).

Stars
Fig. 8 — Stars

We usu­al­ly don’t want any stars or oth­er signs. We want to have blank cells, how­ev­er, the Flash Fill option doesn’t work  with spaces. That’s why we can use the Fil­ter option, which we can find in the Data tab (Fig. 9). In the Fil­ter option, we want to show only this sign (a star).

Filter option
Fig. 9 — Fil­ter option

Now, we’re left only with stars (Fig. 10). We have to select the range (Ctrl + Shift + ↓) and press the Delete key to delete all the signs.

Selected range
Fig. 10 — Select­ed range

Then we can turn off the fil­ter. We can do it man­u­al­ly, by press­ing the fil­ter icon and select­ing the Clear Fil­ter From “Mid­dle names” option (Fig. 11) or by press­ing the Ctrl + Shift + L key combination.

Turning off the filter
Fig. 11 — Turn­ing off the filter

Now, we have mid­dle names only in places, where they real­ly exist, and blank cells, where there aren’t any mid­dle names (Fig. 12)

Extracted names
Fig. 12 — Extract­ed names

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

IF function and logical tests

Today, we will dis­cuss log­i­cal tests and the IF func­tion in Excel. 

IF func­tion and log­i­cal tests

Let’s start with log­i­cal test. We want to check whether our stu­dents passed the test, i.e. whether they achieved 70 points (cell D2). We need a for­mu­la that checks if the num­ber from cell B5 is greater or equal to the val­ue from in cell D2. We aslo have to lock the val­ue from cell D2 by press­ing F4 key (Fig. 1). 

Logical test with locked cell D2
Fig. 1 — Log­i­cal test with locked cell D2 

After copy­ing the for­mu­la down, we have our log­i­cal answers (Fig. 2)

Logical answers
Fig. 2 — Log­i­cal answers

Log­i­cal answers, how­ev­er, aren’t human answers. If we want some­thing sim­pler, like pass/fail, we need to use the IF func­tion in cell D5 (Fig. 3). 

IF function inserting simpler answers
Fig. 3 — IF func­tion insert­ing sim­pler answers

After copy­ing it down, we have the answers that we want, instead of log­i­cal ones. If the log­i­cal test returns False, our IF func­tion returns text Fail. If the log­i­cal test returns True, our IF func­tion returns text Pass (Fig. 4)

Simpler/human answers
Fig. 4 — Simpler/human answers

Some­times, we want to know how many more points a stu­dent needs to pass their exam. In that case, we also use the IF func­tion. This time, how­ev­er, we are chang­ing the direc­tion of our test. We need to check if the val­ue from cell B5 is low­er than the val­ue from cell D2 (70 points). If it is low­er, it means that the stu­dent failed the exam. Cal­cu­lat­ing the num­ber of miss­ing points is a sim­ple, math­e­mat­i­cal oper­a­tion. We just have to sub­tract the val­ue from cell B5 (62 points) from the val­ue in cell D2 (70 points). How­ev­er, if a stu­dent passed the exam, we don’t need to cal­cu­late any­thing, so we’re return­ing 0 points (Fig. 5). 

=IF(B5<$D$2,$D$2‑B5,0)

IF function calculating the number of missing points
Fig. 5 — IF func­tion cal­cu­lat­ing the num­ber of miss­ing points

After copy­ing it down, we can see that one stu­dent needs 8 points to pass, and anoth­er one needs 35. The stu­dents who passed the exam, don’t need any more points, that’s why IF func­tion returned 0 for them (Fig. 6). 

The number if missing points
Fig. 6 — The num­ber if miss­ing points

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