Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Mike S
 
Posts: n/a
Default Alphabetically reorder a text string with multiple words

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.

For any help I would be really grateful.
Thanks
Mike
  #2   Report Post  
Grandslam90
 
Posts: n/a
Default Alphabetically reorder a text string with multiple words


I posted this message here earlier and also posted it to a microsoft
site without fully realising that it is getting duplicated here and
there ......

Sorry :-(
Mike


--
Grandslam90
------------------------------------------------------------------------
Grandslam90's Profile: http://www.excelforum.com/member.php...o&userid=17408
View this thread: http://www.excelforum.com/showthread...hreadid=480087

  #3   Report Post  
Bernie Deitrick
 
Posts: n/a
Default Alphabetically reorder a text string with multiple words

Mike,

Copy the code below into a codemodule, and use the function like

=ISort(A1)

where A1 has your string to be re-ordered.

HTH,
Bernie
MS Excel MVP

Function ISort(inCell As Range) As String
Dim myVals As Variant
Dim i As Integer

myVals = Split(inCell.Value, " ")

BubbleSort myVals

For i = LBound(myVals) To UBound(myVals)
ISort = ISort & myVals(i) & " "
Next i

ISort = Trim(ISort)

End Function

Function BubbleSort(List As Variant)
' Sorts an array using bubble sort algorithm
Dim First As Integer
Dim Last As Integer
Dim i As Integer
Dim j As Integer
Dim Temp As Variant

First = LBound(List)
Last = UBound(List)
For i = First To Last - 1
For j = i + 1 To Last
If List(i) List(j) Then
Temp = List(j)
List(j) = List(i)
List(i) = Temp
End If
Next j
Next i

End Function
"Mike S" <Mike wrote in message
...
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.

For any help I would be really grateful.
Thanks
Mike



  #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)," ")




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Justify text across multiple columns fins2r Excel Discussion (Misc queries) 4 October 26th 05 05:07 PM
want to remove all text characters equal to one character in length from text string [email protected] Excel Worksheet Functions 1 April 18th 05 12:25 AM
Finding Specific Text in a Text String Peter Gundrum Excel Worksheet Functions 9 April 10th 05 07:21 PM
multiple text files URGENT tasha Excel Discussion (Misc queries) 1 December 19th 04 05:44 PM
importing multiple text files??? tashayu Excel Discussion (Misc queries) 0 December 19th 04 02:43 PM


All times are GMT +1. The time now is 09:44 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"