Hi, welcome to the forum

You cannot do this - the way you want - with formulas.

Have you considered using SORT? Alternatively, you would need a macro