For teachers / Answer key
Answer key: Working with Text
For teachers. This page is kept out of search engines and linked only from the teachers page. Students can see the same answers in a lesson with Show answer. Any formula that gives the right values counts.
1. Joining text (Intermediate, 4 min)
In
D2, build a display name from the first and last names with a space in between:=A2&" "&C2. Then copy it down toD7.D2:D7=A2&" "&C2then copy it across the range
Shows D2: Ines Moreau, D3: Tomasz Kowal, D4: Ravi Shah, D5: Lucía Ferreira, D6: Owen Doyle, D7: Mei Tanaka
Staff directories often list people surname first. In
E2:E7, use CONCAT to build names like Moreau, Ines.E2:E7=CONCAT(C2, ", ", A2)then copy it across the range
Shows E2: Moreau, Ines, E3: Kowal, Tomasz, E4: Shah, Ravi, E5: Ferreira, Lucía, E6: Doyle, Owen, E7: Tanaka, Mei
Some people have a middle name and some don't. In
F2:F7, build each full name with TEXTJOIN, using a space as the delimiter and TRUE to skip empty cells:=TEXTJOIN(" ", TRUE, A2:C2)F2:F7=TEXTJOIN(" ", TRUE, A2:C2)then copy it across the range
Shows F2: Ines Moreau, F3: Tomasz Jan Kowal, F4: Ravi Kumar Shah, F5: Lucía Ferreira, F6: Owen Patrick Doyle, F7: Mei Tanaka
TEXTJOIN can also squeeze a whole column into one cell. In
B9, list everyone's first name, separated by a comma and a space: Ines, Tomasz, …B9=TEXTJOIN(", ", TRUE, A2:A7)
Shows B9: Ines, Tomasz, Ravi, Lucía, Owen, Mei
2. LEFT, RIGHT, MID and LEN (Intermediate, 4 min)
In
B2:B8, pull the two-letter region from the start of each reference with LEFT.B2:B8=LEFT(A2, 2)then copy it across the range
Shows B2: NY, B3: CA, B4: TX, B5: WA, B6: FL, B7: OR, and 1 more
In
C2:C8, take the four-digit sequence number from the end of each reference with RIGHT.C2:C8=RIGHT(A2, 4)then copy it across the range
Shows C2: 0581, C3: 1172, C4: 0046, C5: -913, C6: 1208, C7: 0337, and 1 more
The year sits in the middle: it starts at character 4 and is 4 characters long. In
D2:D8, extract it with MID.D2:D8=MID(A2, 4, 4)then copy it across the range
Shows D2: 2024, D3: 2023, D4: 2025, D5: 2024, D6: 2025, D7: 2023, and 1 more
Every valid reference is 12 characters long. In
E2:E8, count the characters in each one with LEN, and look for the odd one out.E2:E8=LEN(A2)then copy it across the range
Shows E2: 12, E3: 12, E4: 12, E5: 11, E6: 12, E7: 12, and 1 more
3. Splitting text at a character (Intermediate, 6 min)
In
C2:C8, find the position of the @ in each email address:=FIND("@", B2)C2:C8=FIND("@", B2)then copy it across the range
Shows C2: 15, C3: 7, C4: 10, C5: 13, C6: 10, C7: 6, and 1 more
In
D2:D8, take everything before the @ as the username. Use LEFT with the position from column C, minus 1 so the @ itself is left out.D2:D8=LEFT(B2, C2-1)then copy it across the range
Shows D2: adaeze.okonkwo, D3: mats.l, D4: jferreira, D5: ken.nakamura, D6: s.brennan, D7: yusuf, and 1 more
In
E2:E8, take everything after the @ as the domain. MID should start one character past the @. For the length,LEN(B2)is always enough, because MID stops at the end of the text.E2:E8=MID(B2, C2+1, LEN(B2))then copy it across the range
Shows E2: example.com, E3: studio.example.net, E4: example.org, E5: example.com, E6: mail.example.co.uk, E7: example.net, and 1 more
Now the modern shortcut. The names in column A are written Last, First. In
F2:F8, get each first name with=TEXTAFTER(A2, ", "), which returns everything after the comma and space.F2:F8=TEXTAFTER(A2, ", ")then copy it across the range
Shows F2: Adaeze, F3: Mats, F4: Joana, F5: Ken, F6: Siobhan, F7: Yusuf, and 1 more
In
G2:G8, get each last name with TEXTBEFORE: everything before the comma.G2:G8=TEXTBEFORE(A2, ",")then copy it across the range
Shows G2: Okonkwo, G3: Lindqvist, G4: Ferreira, G5: Nakamura, G6: Brennan, G7: Haddad, and 1 more
4. Cleaning up messy text (Intermediate, 5 min)
The imported names in column A have extra spaces at the start, at the end and in the middle. In
D2:D8, tidy them with=TRIM(A2).D2:D8=TRIM(A2)then copy it across the range
Shows D2: priya RAMAN, D3: JONAS WEBER, D4: lena o'connor, D5: marcus bell, D6: Aiko tanaka, D7: SAMUEL okafor-reid, and 1 more
Now fix the capitals too. Change
D2:D8so that TRIM sits inside PROPER:=PROPER(TRIM(A2))D2:D8=PROPER(TRIM(A2))then copy it across the range
Shows D2: Priya Raman, D3: Jonas Weber, D4: Lena O'Connor, D5: Marcus Bell, D6: Aiko Tanaka, D7: Samuel Okafor-Reid, and 1 more
Email addresses don't care about capitals, but mixed case looks messy and trips up duplicate checks. In
E2:E8, convert each email to lowercase.E2:E8=LOWER(B2)then copy it across the range
Shows E2: priya.raman@example.com, E3: jweber@example.net, E4: lena.oconnor@example.org, E5: marcus.bell@example.com, E6: aiko.t@example.co.uk, E7: s.okafor-reid@example.org, and 1 more
Booking references should be in capitals. In
F2:F8, convert them with UPPER.F2:F8=UPPER(C2)then copy it across the range
Shows F2: BK 2290, F3: BK 2291, F4: BK2292, F5: BK 2293, F6: BK 2294, F7: BK 2295, and 1 more
Remove those inner spaces by substituting every space with nothing (
""). ChangeF2:F8to=SUBSTITUTE(UPPER(C2), " ", "")F2:F8=SUBSTITUTE(UPPER(C2), " ", "")then copy it across the range
Shows F2: BK2290, F3: BK2291, F4: BK2292, F5: BK2293, F6: BK2294, F7: BK2295, and 1 more
5. Formatting numbers in text with TEXT (Intermediate, 5 min)
First, see the problem. In
D2, join a label to the amount exactly like this:="Total: "&B2D2="Total: "&B2
Shows D2: Total: 1234.5
Fix it with TEXT. Change
D2to="Total: "&TEXT(B2, "$#,##0.00")and copy it down toD7.D2:D7="Total: "&TEXT(B2, "$#,##0.00")then copy it across the range
Shows D2: Total: $1,234.50, D3: Total: $860.00, D4: Total: $2,475.25, D5: Total: $315.80, D6: Total: $1,099.99, D7: Total: $4,200.00
Do the same for the due dates. In
E2:E7, build labels like Due Mar 21, 2025 using the format"mmm d, yyyy".E2:E7="Due "&TEXT(C2, "mmm d, yyyy")then copy it across the range
Shows E2: Due Mar 21, 2025, E3: Due Apr 2, 2025, E4: Due Mar 7, 2025, E5: Due Apr 15, 2025, E6: Due Mar 14, 2025, E7: Due May 1, 2025
TEXT can format the result of any calculation. In
B9, build the line Outstanding: $10,185.54 by wrapping a SUM of the amounts in TEXT.B9="Outstanding: "&TEXT(SUM(B2:B7), "$#,##0.00")
Shows B9: Outstanding: $10,185.54
Last one. In
B10, show the earliest due date with its weekday, like Next due: Friday, Mar 7. Use MIN to find the earliest date, and the format"dddd, mmm d".B10="Next due: "&TEXT(MIN(C2:C7), "dddd, mmm d")
Shows B10: Next due: Friday, Mar 7
6. Split and clean text: TEXTSPLIT and REGEX (Advanced, 7 min)
The sign-up in
A2holds a name, an email and a phone number, separated by a comma and a space. InC2, split it into three cells:=TEXTSPLIT(A2, ", ")C2=TEXTSPLIT(A2, ", ")
Shows C2: Ana Lopez, D2: ana.lopez@example.com, E2: (555) 123-4567
The phone number in
E2has brackets, a space and a dash. InC4, replace everything that is not a digit with nothing:=REGEXREPLACE(E2, "\D", "")C4=REGEXREPLACE(E2, "\D", "")
Shows C4: 5551234567
Which emails in
G2:G6look valid? A rough pattern: some text, an @, more text, a dot, then letters. InH2:=REGEXTEST(G2:G6, "^\S+@\S+\.[a-z]+quot;)H2=REGEXTEST(G2:G6, "^\S+@\S+\.[a-z]+quot;)
Shows H2: TRUE, H3: FALSE, H4: TRUE, H5: FALSE, H6: TRUE
The note in
A9mentions an invoice somewhere in the middle. InC11, pull out "INV-" followed by its digits:=REGEXEXTRACT(A9, "INV-\d+")C11=REGEXEXTRACT(A9, "INV-\d+")
Shows C11: INV-2041