Split, Deduplicate, and Sort Text from an Excel Range
Question details
Create one alphabetically sorted, comma-separated list of unique ingredients or allergens from B2:B5.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Each cell in the range may contain several comma-separated text values.
- Observed behavior
- The desired result is a single list containing each value once, sorted alphabetically.
Check that the source values in B2:B5 are separated by commas and include at least one nonblank item. The formula requires an Excel version that supports TEXTSPLIT, UNIQUE, SORT, FILTER, and LET.
Use a formula to combine, split, and sort the range
Use this formula to produce a list that updates when the values in B2:B5 change.
The formula joins the range, splits the text into rows at each comma, trims spaces, removes blank items and duplicates, sorts the remaining values, and joins them into one cell.
In Excel, click an empty cell outside B2:B5 where you want the finished list to appear.
Enter =LET(items,TRIM(TEXTSPLIT(TEXTJOIN(",",TRUE,B2:B5),,",")),TEXTJOIN(", ",TRUE,SORT(UNIQUE(FILTER(items,items<>""))))) and press Enter.
Compare the output cell with B2:B5. Each nonblank item should appear once, in alphabetical order, separated by a comma and a space.

Create a unique, sorted list in WPS Spreadsheets
Use WPS Spreadsheets to split the combined values, clean and sort them, and build a comma-separated result without relying on TEXTSPLIT.
- 1. Combine the source cells: Open the workbook in WPS Spreadsheets. In an empty cell such as C2, enter =B2&","&B3&","&B4&","&B5. Copy C2 and use Paste Special to paste its value into C2.
- 2. Split and transpose the items: Select C2, choose Data > Text to Columns, and use a comma as the delimiter. Copy the resulting row and use Paste Special > Transpose to paste it vertically starting at D2.
- 3. Trim spaces: In E2, enter =TRIM(D2) and fill the formula down alongside the items in column D. Copy the results in column E and paste them back as values; delete any blank items.
- 4. Remove duplicates and sort: Select the cleaned items in column E, use Data > Remove Duplicates, and then use Data > Sort to sort the remaining values from A to Z.
- 5. Rejoin the list: Enter =E2 in F2. If there is more than one item, enter =F2&", "&E3 in F3 and fill it down to the last item. The final cell in column F contains the combined list.

Frequently Asked Questions
Does the Excel formula include every cell in B2:B5?
Yes. The first TEXTJOIN combines the entire B2:B5 range before TEXTSPLIT separates the individual items.
Will extra spaces around ingredients create duplicates?
The formula uses TRIM to remove ordinary leading and trailing spaces before UNIQUE checks for duplicates. Nonbreaking spaces may need separate cleaning.
What if my values use commas without spaces?
The formula splits on the comma itself, so it handles both "milk,eggs" and "milk, eggs". TRIM removes ordinary spaces around each item.
Why does Excel show a name error for the formula?
Your Excel version may not support one of the functions, particularly TEXTSPLIT. Check your version or use the split-and-sort workflow in WPS Spreadsheets.




