Sub topic 6
Joining Ranges and Skipping Blanks with FILTER
Prerequisites and the working model
This chapter assumes you can enter Google Sheets formulas, reference cells and ranges, and use functions such as TRIM and IFERROR. A range is a group of cells, such as A2:A10. An array is a collection of values that a formula can process as a group.
JOIN combines values into one text string. Its first argument is the delimiter, which is the text placed between values. Its remaining arguments are the values, ranges, or arrays to combine.
=JOIN(", ", A2:A10)This formula joins the values in A2:A10, placing a comma and a space between each value. For example, if the range contains Red, Blue, and Green, the result is:
Red, Blue, GreenHow JOIN handles ranges
A range can contain text, numbers, and blank cells. JOIN reads the values in order from the range and returns one string.
| Range contents | Formula | Result |
|---|---|---|
| Red, Blue, Green | `=JOIN(", ", A2:A4)` | `Red, Blue, Green` |
| Red, blank, Green | `=JOIN(", ", A2:A4)` | `Red, , Green` |
Blank cells can therefore create unwanted separators. This often happens when a sheet contains optional tags, incomplete records, or imported data.
A delimiter is still added around an empty value because the empty cell remains part of the input range. To skip blank cells, filter the range before passing it to JOIN.
Filtering out blank cells
FILTER returns only the values that meet a condition. The basic pattern is:
=FILTER(range, condition)To keep only non-blank cells, compare the range with an empty string:
=FILTER(A2:A10, A2:A10<>"")The operator <> means “is not equal to.” Therefore, A2:A10<>"" creates a matching TRUE or FALSE result for each cell. FILTER keeps the cells whose result is TRUE.
Place that filtered array inside JOIN:
=JOIN(", ", FILTER(A2:A10, A2:A10<>""))Now blank cells do not produce extra commas. The process has two stages:
Combining FILTER with cleanup
A cell may look blank but contain spaces. The condition A2:A10<>"" can treat a spaces-only cell as non-blank. Use TRIM when whitespace may be present:
=JOIN(", ", FILTER(TRIM(A2:A10), TRIM(A2:A10)<>""))TRIM removes leading and trailing spaces from each value. Because TRIM(A2:A10) is an array, both the values returned by FILTER and the condition should use the trimmed array.
You can also remove repeated spaces inside each cell with REGEXREPLACE:
=JOIN(", ", FILTER(ARRAYFORMULA(TRIM(REGEXREPLACE(A2:A10, "\s+", " "))), A2:A10<>""))This is useful for imported text, but start with the simpler formula unless the data needs that extra cleanup.
Common errors
#N/AfromFILTER: No cells met the condition. Wrap the complete formula withIFNAif an empty result is acceptable.- Unexpected separators: Check whether the source range contains blank cells or cells containing spaces.
- Wrong delimiter position: In
JOIN, the delimiter comes first:JOIN(delimiter, values). - Too much range: A large range may include labels or unrelated values. Use the smallest range that contains the intended data.
=IFNA(JOIN(", ", FILTER(A2:A10, A2:A10<>"")), "")This returns an empty string when there are no non-blank values.
Exercise
Cells A2:A6 contain Apples, a blank cell, Oranges , a spaces-only cell, and Bananas. Write a formula that returns Apples, Oranges, Bananas with surrounding spaces removed and blank-looking cells skipped.
Show answer
=JOIN(", ", FILTER(TRIM(A2:A6), TRIM(A2:A6)<>""))