LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default sorting text in a string

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
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
Change 3 letter text string to a number string Pete Excel Discussion (Misc queries) 3 December 31st 07 07:47 PM
Sorting By Largest Value In A String [email protected] Excel Programming 1 July 6th 06 07:44 PM
Splitting a text string into string and number mcambrose Excel Discussion (Misc queries) 4 February 21st 06 03:47 PM
string sorting problem NikkoW Excel Programming 1 May 2nd 04 04:59 PM
sorting data in string Mark[_17_] Excel Programming 1 September 16th 03 05:08 PM


All times are GMT +1. The time now is 04:18 PM.

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"