View Single Post
  #5   Report Post  
Harlan Grove
 
Posts: n/a
Default Alphabetically reorder a text string with multiple words

"Mike S" <Mike wrote...
Am trying to figure out if a user-defined function can be created to
alphabetically re-order a text with multiple words.

For example.
"Hotel Paris Hilton" should convert to "Hilton Hotel Paris"
"Paris" is then the last word because "H" is before "P" in the alphabet
"Hilton" is the first word because "i" is before "o" in the Alphabet and so
on and so forth.


Easiest way to do this would be to use add-in functions from Laurent
Longre's MOREFUNC.XLL add-in, available from

http://xcell05.free.fr/english/

If you install MOREFUNC.XLL, try the array formula

=MCONCAT(VSORT(MID(A1,SMALL(IF(MID(" "&A1,INTVECTOR(1024,1),1)="
",INTVECTOR(1024,1)),
INTVECTOR(WORDCOUNT(A1),1)),SMALL(IF(MID(A1&" ",INTVECTOR(1024,1),1)=" ",
INTVECTOR(1024,1)),INTVECTOR(WORDCOUNT(A1),1))-SMALL(IF(MID(" "&A1,
INTVECTOR(1024,1),1)="
",INTVECTOR(1024,1)),INTVECTOR(WORDCOUNT(A1),1))), ,1)," ")

or use a defined name like seq referring to =ROW(INDIRECT("1:1024")), which
would allow shortening the formula to

=MCONCAT(VSORT(MID(A1,SMALL(IF(MID(" "&A1,seq,1)="
",seq),INTVECTOR(WORDCOUNT(A1),1)),
SMALL(IF(MID(A1&" ",seq,1)=" ",seq),INTVECTOR(WORDCOUNT(A1),1))
-SMALL(IF(MID(" "&A1,seq,1)=" ",seq),INTVECTOR(WORDCOUNT(A1),1))),,1)," ")