Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Sort text that is deliminated within a cell

Ken,

Sorry for the long response, but thank you very much for the code as
it works very nice. Thanks a lot!.

Mark


Ken Johnson wrote:
Oops!

Sorry about this, But I didn't notice the disappearance of one of the
substrings due to a bit of confusion with the split method returning a
zero base array, while the other arrays were one base.

this version retains all substrings...

Public Sub SortCellStrings()
Dim rngSortRange As Range
Set rngSortRange = Application.InputBox( _
"Select the range of cells for internal sorting", _
"Sort Cell Contents", Selection.Address, , , , , 8)
Dim rngCell As Range
Dim StrSubStrings() As String
Dim strNumPart As String
Dim vaArray() As Variant
Dim lNum As Long
Dim I As Integer
Dim J As Integer
For Each rngCell In rngSortRange
StrSubStrings = Split(rngCell.Value, ", ")
For I = 0 To UBound(StrSubStrings)
For J = 1 To Len(StrSubStrings(I))
Select Case Mid(StrSubStrings(I), J, 1)
Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
strNumPart = strNumPart & Mid(StrSubStrings(I), J,
1)
End Select
Next J
ReDim Preserve vaArray(2, I + 1) As Variant
vaArray(1, I + 1) = StrSubStrings(I)
vaArray(2, I + 1) = CLng(strNumPart)
strNumPart = ""
Next I
BubbleSort vaArray:=vaArray
ReDim strFinal(0 To UBound(vaArray, 2)) As String
For I = 0 To UBound(vaArray, 2) - 1
strFinal(I) = vaArray(1, I + 1)
Next I
rngCell.Value = Join(strFinal, ", ")
Next rngCell
End Sub


Public Sub BubbleSort(vaArray() As Variant)
Dim J As Integer, k As Integer, l As Integer, n As Integer, t$, u$
n = UBound(vaArray, 2)
For l = 0 To n
J = l
For k = J + 1 To n
If vaArray(2, k) <= vaArray(2, J) Then
J = k
End If
Next k
If l < J Then
t$ = vaArray(2, J)
u$ = vaArray(1, J)
vaArray(2, J) = vaArray(2, l)
vaArray(1, J) = vaArray(1, l)
vaArray(2, l) = t$
vaArray(1, l) = u$
End If
Next l
End Sub

Ken Johnson


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,073
Default Sort text that is deliminated within a cell

Hi Mark,

You're welcome.
Thanks for the feedback.

Ken Johnson

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
Text not continuing to wrap for large block of text in Excel cell Mandra Charts and Charting in Excel 1 May 15th 06 07:13 PM
Help with this conditional IF statement C-Dawg Excel Discussion (Misc queries) 3 May 15th 06 06:01 PM
Cell Capacity - text i2meek Excel Discussion (Misc queries) 4 March 13th 06 12:06 AM
Can you keep text from one cell showing over the next cell? Sean VandeWall Excel Discussion (Misc queries) 2 February 22nd 06 08:20 PM
Shade cell according to text? Ltat42a Excel Discussion (Misc queries) 0 January 3rd 06 06:37 PM


All times are GMT +1. The time now is 03:00 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"