Sub topic 5
Combining Values into One String with JOIN
Assume you can enter formulas, reference cell ranges, and use functions such as FILTER and TRIM. In this chapter, you will use JOIN to turn several cell values into one text string.
What JOIN does
JOIN combines values in an array, range, or list of arguments. It places the delimiter between neighboring values.
A delimiter is the text that separates items. Common delimiters include a comma, a comma followed by a space, a pipe (|), and a line break.
The delimiter is the first argument:
=JOIN(delimiter, value_or_array1, [value_or_array2, ...])For example, suppose cells A2:A4 contain:
| Cell | Value |
|---|---|
| A2 | Red |
| A3 | Green |
| A4 | Blue |
This formula combines the range into one string:
=JOIN(", ", A2:A4)The result is:
Red, Green, BlueThe cells remain separate. JOIN only creates a text result in the cell containing the formula.
Joining a range
The delimiter controls the appearance of the result:
=JOIN(" | ", A2:A4)This returns:
Red | Green | BlueYou can also join values directly instead of referencing a range:
=JOIN(" - ", "ORD", "10492", "Open")The result is:
ORD - 10492 - OpenJOIN converts the values into one string. If a value is numeric, the result is still text because the formula produces text.
Joining values while skipping blanks
A range may contain empty cells. If you join the range directly, the empty positions can still affect the separators. Filter the range first when you want only populated cells.
=JOIN(", ", FILTER(A2:A10, A2:A10<>""))FILTER returns only the cells whose value is not an empty string. JOIN then places , between those remaining values.
For example, if the range contains Red, a blank cell, and Blue, the result is:
Red, BlueWithout FILTER, the output may contain an extra separator where the blank cell occurs.
The data flow is:
Cleaning values before joining
Values may contain accidental spaces. Apply TRIM to each value before joining it. TRIM removes extra spaces at the beginning and end of text.
=JOIN(", ", ARRAYFORMULA(TRIM(FILTER(A2:A10, A2:A10<>""))))This formula performs three steps:
FILTERkeeps populated cells.ARRAYFORMULA(TRIM(...))removes surrounding spaces from every remaining value.JOINcombines the cleaned values with a comma and a space.
For example, values such as Red and Blue become:
Red, BlueCommon errors
- Put the delimiter first.
=JOIN(A2:A4, ", ")treats the range as the delimiter and does not express the intended operation. - Check the output cell for existing content if a formula returns an array from another function. A blocked output range is a common issue when combining functions.
- Remember that
JOINdoes not remove duplicate values or sort them. Clean or organize the range separately if needed. - If
FILTERfinds no matching cells, it can return an error. UseIFERRORwhen an empty result is acceptable.
Exercise
Cells A2:A6 contain Sam, a blank cell, Lee, two spaces, and Mina. Write a formula that returns Sam, Lee, Mina with no extra separators and removes surrounding spaces.
Show answer
=JOIN(", ", ARRAYFORMULA(TRIM(FILTER(A2:A6, A2:A6<>""))))