Use TEXTJOIN function to combine text values with optional delimiter. It is better than CONCATENATE because you can pass a range instead of individual cells and you can ignore empty cells too. Here is a sample use of TEXTJOIN Excel function.
TEXTJOIN Syntax & examples
To combine values in A1:A5 with comma separator, use =TEXTJOIN(",",,A1:A5) To ignore any blank values while concatenating, use =TEXTJOIN(",",TRUE, A1:A5)
TEXTJOIN Syntax: TEXTJOIN(delimiter, ignore empty values, range or list of values)
Why TEXTJOIN? Why not CONCATENATE or & operator?
- TEXTJOIN is easy
To combine values in A1:A5 with CONCATENATE, we have to write =CONCATENATE(A1, A2, A3, A4, A5) or A1&A2&A3&A4&A5
With TEXTJOIN, you can simply say =TEXTJOIN(,,A1:A5)
- Add delimiters
You can comma separate or add other delimiters when combining text with TEXTJOIN. While you can do the same with CONCATENATE, it becomes doubly annoying.
=TEXTJOIN(“, “,,A1:A5) gives you a comma separated text of values in A1:A5
3 Advanced TEXTJOIN uses
Here are three advanced examples of TEXTJOIN.
1. Combine values that meet a criteria
Let’s say you want to combine all player names for kickers team as shown aside. You can use TEXTJOIN with IF formula to do this.
=TEXTJOIN(“, “,TRUE,IF($C$36:$C$63=”kickers”,$B$36:$B$63,””))
The inner IF function returns an array of team members or blank depending on whether they are in kickers or not.
TEXTJOIN then ignores all blank values and returns comma seperated text.
Same formula with FILTER()
You can also use the newly introduced dynamic array function FILTER to do this job.
=TEXTJOIN(“, “,,FILTER(B36:B63,C36:C63=”kickers”))
Learn more about Excel Dynamic Array functions.
2. Reverse a text
You can use MID function to split a text value in to an array of characters and then reverse them with TEXTJOIN.
For example, below formula reverses “Chandoo”
=TEXTJOIN(,,MID(“Chandoo”,21-ROW($A$1:$A$20),1))
It works up to 20 letters.
How does it work?
MID(“Chandoo”,21-ROW($A$1:$A$20),1) portion returns an array of 20 items {“”;””;””;””;””;””;””;””;””;””;””;””;””;”o”;”o”;”d”;”n”;”a”;”h”;”C”}
This is then combined by TEXTJOIN to return 00dnahC
3. Substitution cipher with TEXTJOIN
Want to communicate in a secret code with your colleague? You can use substitution cipher to map each letter with another letter of alphabet.
We can use either XLOOKUP or VLOOKUP with TEXTJOIN to encrypt text values like this.
Imagine you have a mapping table as shown aside.
To convert a message in cell H92, use this formula
=TEXTJOIN(,,XLOOKUP(MID(H92,ROW($A$1:$A$20),1),subs[Normal], subs[Code],””))
How does it work?
Using the MID() function, we split the text in H92 into an array of 20 values, one per character.
We then pass these letters to XLOOKUP to find matching [Code] from the subs table.
All these values are finally combined by TEXTJOIN to generated our coded message.
What the function - TEXTJOIN in Excel video
I recently started a series of videos on my Youtube channel to demystify Excel functions. This series is named What the function. Watch below WTF tutorial on TEXTJOIN to learn how to use it.
Download TEXTJOIN Example Workbook
Click here to download the TEXTJOIN example file. Use the sample data and formulas to understand TEXTJOIN function better. Play with the data to create something cool on your own and post your TEXTJOIN ideas in the comments.
TEXTJOIN in use - Excel Risk Map
If you want to get some inspiration on how TEXTJOIN can be a force of good, see this Excel risk map. It uses TEXTJOIN to show risks in a matrix format.
2 Responses to “Excel TEXTJOIN Function – What is it, how to use it & 3 advanced examples”
How about SEQUENCE(20,,20,-1) instead of 21-ROW($A$1:$A$20) giving us a more robust formula
Good addition. As DA functions are not widely available, I did not mention it.