Text: CONCAT, TEXTJOIN, TEXTBEFORE, TEXTAFTER: practice exercises
CONCAT, TEXTJOIN, TEXTBEFORE, TEXTAFTER. 6 exercises on real-looking data, each marked the moment you press Check. The first exercise is below to try now; the full lesson is part of Pro.
In C2, use CONCAT to join each first name and surname, with a space between them.
| A | B | C | |
|---|---|---|---|
| 1 | First name | Surname | Full name |
| 2 | Will | Baker | |
| 3 | Jess | Smith | |
| 4 | Tom | Brown | |
| 5 | Rachel | Ahmed | |
| 6 | Chen | Ali | |
| 7 | Grace | Hall | |
| 8 | Hannah | Hughes | |
| 9 | Alex | Patel | |
| 10 | Kerry | Taylor | |
| 11 | Ben | Bennett |
How it works
CONCAT(a, b, c…) joins text in one go, like a&b&c. TEXTJOIN(separator, TRUE, range) joins a whole range with a separator between each one, and TRUE skips the empty cells.
TEXTBEFORE(text, "@") gives everything before the first @, and TEXTAFTER(text, "@") everything after it. Add -1 as a third argument to use the last one instead of the first.
=CONCAT(A2,".",B2) =TEXTJOIN(", ",TRUE,B3:E3) =TEXTBEFORE(C2,"@") =TEXTAFTER(A4," ",-1)
Joining text
You've joined text with &: =A2&" "&B2. Two functions do the same job:
CONCAT(A2," ",B2)joins everything you list, in order. It saves typing lots of & signs.TEXTJOIN(", ",TRUE,B2:E2)joins a whole range, putting the separator between each item. TRUE means skip empty cells, so you don't get double commas.
Worked example: splitting
| A | B | C | |
|---|---|---|---|
| 1 | First | Last | |
| 2 | Amira | Shah | amira.shah@company.co.uk |
| 3 | Ben | Lowe | b.lowe@company.co.uk |
| 4 | Cara Jane Wood |
=TEXTBEFORE(C2,"@")in D2. TEXTBEFORE takes everything before the first @: amira.shah.=TEXTAFTER(C2,"@")in D2. TEXTAFTER takes everything after it: company.co.uk.=TEXTAFTER(A4," ",-1)in D4. Cara has a middle name. A third argument of -1 means the last space, so you get only the surname, Wood.
One inside the other
To take out a middle part, such as 4821 from NTH-4821-B, put one inside the other: TEXTAFTER(A2,"-") gives 4821-B, and TEXTBEFORE of that, before the "-", gives 4821.
TEXTBEFORE and TEXTAFTER are in Excel 365 and Excel 2024, but not Google Sheets. In older Excel or in Sheets, use LEFT, MID and FIND.
What you'll practise
- In C2, use CONCAT to join each first name and surname, with a space between them.
- Staff IDs are the department code, a dash, then the number with 4 digits: department ABC and number 37 would make ABC-0037. In D2, use CONCAT and TEXT(C2,"0000") to build each ID.
- In F2, list each person's skills in one cell, separated by a comma and a space, with no extra commas for the empty boxes.
- Each person's username is the part of their email before the @. In C2, use TEXTBEFORE to take it out.
- Some people gave a middle name too. In B2, take out each surname: everything after the last space.
- Order codes look like NTH-4821-B, but each part can be a different length. In B2, take out the middle part, between the two dashes.
Guides with worked examples: Split first and last names in Excel · TEXTSPLIT: splitting text into cells with a formula · Combine first and last names in Excel: &, CONCAT and TEXTJOIN · LEFT, MID and RIGHT: taking part of a code or a postcode