7

In google sheets I have this string:

salmon,fries,peas,coleslaw,onion,garlic,chicken,pancetta,creme fraiche,onion,garlic,chicken,pancetta,creme fraiche,onion,garlic,chicken,pancetta,creme fraiche,gf pizza,gf pizza,pepperoni pizza

I would like to split it by the , character, sort it and textjoin the result.

The overall function I'm working with is this:

=textjoin(",", true, sort(split(textjoin(",",true,$D$2:$D$22), ","), 1, true))

So it looks to me like the sort function call is not working, but obviously the input to it is not a range of cells but a list (?) of strings produced by splitting a combination of strings.

The inner-most textjoin is required because the cells being joined contain lists of strings separated by , characters. I am trying to sort every string from every cell in one large list.

1 Answer 1

6
=textjoin(",", true, sort(transpose(split(textjoin(",",true,$D$2:$D$22), ",")), 1, true))

SORT only sorts by row and in the case of SPLIT it returns a single row. All we have to do is TRANSPOSE that so that it can be sorted correctly.

2
  • 1
    ...thus a simple =TEXTJOIN(",", TRUE, SORT($D$2:$D$22)) will return the same result
    – JohnSUN
    Commented Sep 5, 2022 at 13:14
  • No, it doesn't.
    – Matt W
    Commented Sep 5, 2022 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.