VLOOKUP all matches and combine them

Some­times, we want to find all the matched val­ues and com­bine them into one text string, i.e., we want o VLOOKUP all matched val­ues and then com­bine them.

VLOOKUP all match­es and com­bine them

I will give you two solu­tions. The first solu­tion will work from Excel 2019, and the sec­ond one will work in Dynam­ic Array Excel. First of all, we have to check if our rep­re­sen­ta­tive comes from the coun­try we are look­ing at. Let’s take a rep­re­sen­ta­tive from Spain. There is only one rep­re­sen­ta­tive of Spain in our exam­ple. We can check it using the IF func­tion, where we have to cre­ate a prop­er log­i­cal test. We have to take into con­sid­er­a­tion the Coun­try col­umn, so let’s write it by select­ing the col­umn and click­ing the F4 key to lock it. Then, we have to check if the val­ues from the col­umn are equal to just one coun­try (Spain) by click­ing the cell with the name of Spain (D4). It means that cell D4 will be com­pared to each cell from the Coun­try col­umn indi­vid­u­al­ly (Fig. 1)

Comparison to each cell
Fig. 1 Com­par­i­son to each cell

The log­i­cal test will return TRUE only in the case of Spain. In the case of oth­er coun­tries, it will return FALSE. If the log­i­cal test is in an array, we can choose prop­er, cor­re­spond­ing result as a return val­ue. We just need to select an array of the same size, which, in our case, is the Rep­re­sen­ta­tive col­umn. Then, we click the F4 key to lock it. When the log­i­cal test returns FALSE, we want to see an emp­ty text string, so we have to write a space in dou­ble quotes. Let’s close the func­tion with a paren­the­sis (Fig. 2)

=IF($A$2:$A$14=D2,$B$2:$B$14,” ”)

IF function
Fig. 2 IF function

Since I’m work­ing in Dynam­ic Array Excel, Excel spills the results to the whole col­umn (Fig. 3).

IF function results
Fig. 3 IF func­tion results

We can see that we have only one rep­re­sen­ta­tive of Spain, and many emp­ty cells. If we want to find the remain­ing rep­re­sen­ta­tives, we have to join the infor­ma­tion we have. To do that, we can use the TEXTJOIN func­tion, which is avail­able from Excel 2019. We have to give the func­tion a delim­iter. Let’s write a com­ma and a space in dou­ble quotes. Then, we have to decide whether we want to ignore emp­ty cells. We def­i­nite­ly do, so let’s write TRUE, or its short­er ver­sion, which is 1. Then, we just have to close the whole for­mu­la once again (Fig. 4).

=TEXTJOIN(“, “,1,IF($A$2:$A$14=D2,$B$2:$B$14,” ”))

TEXTJOIN function
Fig. 4 TEXTJOIN function

After enter­ing the for­mu­la and copy­ing it down, we have our results (Fig. 5). 

TEXTJOIN function results
Fig. 5 TEXTJOIN func­tion results

When we are in Dynam­ic Array Excel, we can use the FILTER func­tion instead of the IF func­tion. This func­tion just fil­ters our data. Let’s write FILTER func­tion. Our data is locat­ed only in one col­umn, which is the Rep­re­sen­ta­tive col­umn, so we have write the range and lock it with the F4 key. Then, we have to cre­ate an array of the same size with log­i­cal val­ues of TRUE or FALSE. It means that we have to cre­ate the same log­i­cal test as we did with the IF func­tion. Let’s add the Coun­try col­umn (A2:A14), F4 key to lock it, then an equal sign to check whether any of the val­ue from the Coun­try col­umn is equal to Spain (D2). After clos­ing it, we have a ready for­mu­la (Fig. 6).

=FILTER($B$2:$B$14,A$2:$A$14,=D2)

FILTER function
Fig. 6 FILTER function

We can see that Spain has only one rep­re­sen­ta­tive, but Poland has got three (Fig. 7). 

FILTER function results
Fig. 7 FILTER func­tion results

That’s why we have to put our FILTER func­tion results into the TEXTJOIN func­tion. And, once again, we have to write a com­ma and a space in dou­ble quotes. Then, we have to decide that we want to ignore emp­ty cells and close the whole for­mu­la (Fig. 8)

=TEXTJOIN(“, “,1,FILTER($B$2:$B$14,A$2:$A$14=D2))

TEXTJOIN with FILTER function
Fig. 8 TEXTJOIN with FILTER function

We can see that the results in the first solu­tion and in the sec­ond solu­tion are the same (Fig. 9)

Results
Fig. 9 Results

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

Combine text with different delimiters

Today, we are going to com­bine text with two, dif­fer­ent delim­iters. In our exam­ple, we have shop and street names. We want to put a semi­colon between each shop and street name. How­ev­er, between street and shop names we want to put anoth­er sym­bol, which is a pipe. What is impor­tant in our exam­ple, is the fact that not all cells are filled. We want to just ignore them while com­bin­ing text (Fig. 1).

Com­bine text with dif­fer­ent delimiters
Fig. 1 — Text to combine

This task is very sim­ple in Excel 2019 and new­er ver­sions because we have the TEXTJOIN func­tion. In the first argu­ment of this func­tion, we are putting the delim­iter. We can even put more than one delim­iter. In our exam­ple, the delim­iters are placed in cells D9 and E9, so let’s put them in the for­mu­la and let’s lock them by press­ing the F4 key. When we put more than one delim­iter in the TEXTJOIN func­tion, the func­tion will use them alter­na­tive­ly, which means that first, it will use the semi­colon, then the pipe, then the semi­colon and so on. In next argu­ment we have to decide whether we want to ignore emp­ty cells or not. In this case, as I said ear­li­er, it’s very impor­tant for us to ignore them, so we are writ­ing TRUE or 1. The last argu­ment we need is just text, i.e. the range with text. Let’s close the for­mu­la (Fig. 2)

=TEXTJOIN($D$9:$E$9,1,B2:G2)

Fig. 2 — For­mu­la for com­bin­ing text

After putting it into the cell, let’s copy it down. We have the results. We can see there are semi­colons between shop and street names, and pipes between street and shop names (Fig. 3).

Fig. 3 — Com­bined text

In the TEXTJOIN for­mu­la, delim­iters ori­en­ta­tion is not impor­tant. They can be hor­i­zon­tal or vertical.

We can even hard­code them here by select­ing first argu­ment and press­ing the F9 key to eval­u­ate it. Now, they are writ­ten as text (Fig. 4).

=TEXTJOIN({“;”,”|”},1,B2:G2)

Fig. 4 — Hard­code delimiters

We can leave them like that and the for­mu­la will work the same. 

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

Combine Text from Two or more Cells

Today, we are going to com­bine or con­cate­nate two or more texts togeth­er. Let’s start with cre­at­ing full names. It is a sim­ple exam­ple with two texts. We can use the CONCATENATE func­tion, or, if you have Excel 2019 or a new­er one, you can just use the CONCAT func­tion which com­bines two text ranges. The CONCATENATE func­tion can­not com­bine ranges, only sin­gle cells. How­ev­er, in our exam­ple, it does­n’t mat­ter because when we com­bine the first name and the last name, in real­i­ty, we want to com­bine three texts as there is a delim­iter between the first and last name. That’s why we have to add, let’s say, a space. The space should be in dou­ble quotes because it is a text (Fig. 1).

Com­bine Text from Two or more Cells

=CONCATENATE(A2,” “,B2)

CONCATENATE function
Fig. 1 CONCATENATE function

After enter­ing and copy­ing it down, we have full names (Fig. 2). 

 Full names
Fig. 2 Full names

If you don’t like using the func­tion, you can use the amper­sand sign (&) to com­bine texts. How­ev­er, while using the sign, it is impor­tant to put the sign between each point of con­nec­tion. It means that the & sign must be placed between the first cell address and the space, and between the space and anoth­er cell address (Fig. 3) 

=A2&” “&B2

Ampersand signs in a formula
Fig. 3 Amper­sand signs in a formula

After enter­ing the for­mu­la, we have the same results as after using a func­tion (Fig. 4). It is up to you which one you choose. 

The same results
Fig. 4 The same results

In our sec­ond exam­ple, we want to com­bine more than one text togeth­er, i.e., the first, mid­dle and last name. We will use the CONCATENATE func­tion once more, but this time we are click­ing on the insert func­tion com­mand near the for­mu­la bar and we can see that a Func­tion Argu­ment win­dow appeared. In the win­dow, we have argument/text box­es where we will write our text. We can choose a text from a cell (press Tab). In the Text2 bar, we can write a space. When we press the Tab key, Excel will add dou­ble quotes for us. In the Text3 bar there will be cell B2. In the next bar below, we do the same with writ­ing a space. In the last bar, we place cell C2. We can even see our for­mu­la result straight in the Func­tion Win­dow (Fig. 5).

=CONCATENATE(A2,” “,B2,” “,C2)

Function Arguments window
Fig. 5 Func­tion Argu­ments window

After enter­ing the for­mu­la, we have our results (Fig. 6). In this exam­ple, using the Insert Func­tion com­mand was quite fast. 

Formula results
Fig. 6 For­mu­la results

I have also pre­pared one more func­tion that exists from Excel 2019. It is called TEXTJOIN. It can com­bine text from ranges with the same delim­iter. In our case, the delim­iter is a space, so we have to write a space in dou­ble quotes. Then, we have to decide if we want to ignore emp­ty cells. In most cas­es yes, so we can write either TRUE or 1. Let’s write 1 because it is short­er. Then, we are select­ing the text range, which is the cells that we want to join (Fig. 7)

=TEXTJOIN(“ “,1,A2:C2)

TEXTJOIN function
Fig. 7 TEXTJOIN function

After enter­ing the for­mu­la and copy­ing it down, we have our results (Fig. 8)

TEXTJOIN function results
Fig. 8 TEXTJOIN func­tion results

While com­bin­ing many texts, it is very impor­tant to choose prop­er func­tion. Let’s assume that some peo­ple don’t have mid­dle names. In such a case, the TEXTJOIN func­tion will ignore emp­ty cells and will add only one space. How­ev­er, the CONCATENATE func­tion will leave two spaces. In such a sit­u­a­tion we would have to use the IF func­tion to prop­er­ly address this prob­lem (Fig. 9).

One space and two spaces in different functions
Fig. 9 One space and two spaces in dif­fer­ent functions

Sum­ming up, we joined the first, mid­dle and last name in each row using the CONCATENATE func­tion that com­bines more than two texts, and the TEXTJOIN func­tion that com­bines a range of texts. 

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