How to sort words in a cell alphabetically in Excel
Excel formula
=TEXTJOIN(", ",TRUE,SORT(TEXTSPLIT(A2,,", ")))Split the list into rows, sort it and join it back: =TEXTJOIN(", ",TRUE,SORT(TEXTSPLIT(A2,,", "))).
- Result on the example
- one result per row in
B2, filled down toB6 - Works in
- Excel 2024 and Microsoft 365
- Google Sheets
- Different formula, see below
See it work
The formula is already in B2, filled down to B6. Change any input and the result updates, or edit the formula to experiment.
How it works
SORT works on lists, not on text in one cell, so TEXTSPLIT first turns the cell into a column of words (", " is the row delimiter, the third argument). SORT puts them in order and TEXTJOIN joins them back with the same separator.
Google Sheets' SPLIT returns a row, so TRANSPOSE turns it into a column before SORT.
=TEXTJOIN(", ",TRUE,SORT(TEXTSPLIT(A2,,", ")))Result"blue, green, red"
A2"red, blue, green"The value in A2.
TEXTSPLIT(A2,,", "){3 rows × 1 col} "red", "blue", "green"TEXTSPLIT: Splits text across columns, and rows, at the delimiters you give.- text
A2"red, blue, green" - col_delimiter
(omitted) - row_delimiter
", "
- text
SORT(TEXTSPLIT(A2,,", ")){3 rows × 1 col} "blue", "green", "red"SORT: Sorts rows by one or more columns. is_ascending is TRUE or FALSE.- range
TEXTSPLIT(A2,,", "){3 rows × 1 col} "red", "blue", "green"
- range
TEXTJOIN(", ",TRUE,SORT(TEXTSPLIT(A2,,", ")))"blue, green, red"TEXTJOIN: Joins text with a delimiter between items.- delimiter
", " - ignore_empty
TRUE - text1
SORT(TEXTSPLIT(A2,,", ")){3 rows × 1 col} "blue", "green", "red"
- delimiter
In Google Sheets
Google Sheets needs a different formula: =JOIN(", ",SORT(TRANSPOSE(SPLIT(A2,", ",FALSE)))). On the same data it gives the same result. Here it is running in Google Sheets mode.
Other ways to do it
Each one was run on the same example sheet.
| Formula | Result | When to use it |
|---|---|---|
| =TEXTJOIN(", ",TRUE,SORT(TEXTSPLIT(A2,,", "),,-1)) | red, green, blue, walnut, oak, birch, ash, zinc…Different result | Z to A: -1 is the descending sort order. "red, green, blue" and so on. |
Common mistakes
- Splitting with ", " in the second argument gives a row, and SORT sorts rows by default, so nothing changes. Split into rows, or use
SORT(…,,,TRUE)to sort a row. - Lists typed with and without spaces after commas split badly. Split on "," and TRIM:
SORT(TRIM(TEXTSPLIT(A2,,","))).
Try it yourself
Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.
Sort words in a cell alphabetically
B2, sort the comma-separated words A to Z and join them back with ", ". Fill down to B6.Questions
How do I sort and remove duplicates?
Add UNIQUE: =TEXTJOIN(", ",TRUE,SORT(UNIQUE(TEXTSPLIT(A2,,", ")))).
Can I sort the letters of a single word?
Split into characters instead: =CONCAT(SORT(MID(A2,SEQUENCE(LEN(A2)),1))).
Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.