Home |
Search |
Today's Posts |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
A quick and dirty solution:
Sub SortThisText() Dim SortedLetters(255) As String TextToSort = Application.Selection SortedText = "" For i = 1 To Len(TextToSort) CurrentChar = Mid(TextToSort, i, 1) SortedLetters(Asc(CurrentChar)) = SortedLetters(Asc(CurrentChar)) & CurrentChar Next For i = 1 To 255 SortedText = SortedText & SortedLetters(i) Next MsgBox (SortedText) End Sub This sorts the text based on ASCII codes and pops a message box with the sorted text. You will need to be careful that ASCII order is what you want - in your example you wanted numbers to come after letters so that would need some more logic in the code to achieve that. HTH UKMatt On Aug 25, 10:56 am, RTP wrote: How can I sort a string of text in VBA. For Example - v_text = "gbc3d1aef2" should be sorted to "abcdefg123" Cheers RTP |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Change 3 letter text string to a number string | Excel Discussion (Misc queries) | |||
Sorting By Largest Value In A String | Excel Programming | |||
Splitting a text string into string and number | Excel Discussion (Misc queries) | |||
string sorting problem | Excel Programming | |||
sorting data in string | Excel Programming |