1

Give a sequence of columns, I want to sort each column individually using formula because of some reason.
Eg.

A B C D
4 7 2 5
1 8 1 3
9 3 4
7 4

Expected output

A B C D
1 7 1 3
4 7 2 4
8 3 4
9 5

Is there any way to do that with a formula? Also the formula should take the whole range as input like A1:D4. Any help is appreciated

Edit - My real problem is solving a trick question, it is not related to any real-world dataset. I saw this trick question answered on youtube here - link. While the solution is provided for a single cell and dragged for remaining cells, I wanted to implement it using ArrayFormula for the whole column so that I don't have to keep dragging it again.

I don't know if it is possible or not, or is it valid to solve questions like these in google sheets. Do tell if it's not appropriate in tools like sheets.

0

2 Answers 2

0

Use BYCOL

=BYCOL(A1:D4, LAMBDA(col, SORT(col))) 

BYCOL  LAMBDA  SORT

0

If I understand you correctly this formula should solve:

={SORT(A1:A,1,true),SORT(B1:B,1,true),SORT(C1:C,1,true),SORT(D1:D,1,true)}

enter image description here

EDIT: this formula is based on your last request:

=byrow(A1:A,lambda(r,if(r="",,join("",sort(transpose(split(regexreplace(r&"","(?s)(.{1})","$1 ")," ")))))))

all the strings (number and/or text) contained in the cells of column A will be sorted individually

0

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.