Sorting Chapters

  • Thread starter Thread starter Marc
  • Start date Start date
M

Marc

Hello,
I have a problem in sorting cells, that contain chapter
numbers and text. The following 4 cells

2.1.3 Intro
2.11 External conditions
2.13.3 Risks
2.6 Testing

are wrong sorted. It shall be

2.1.3 Intro
2.6 Testing
2.11 External conditions
2.13.3 Risks

How can I sort it via function or vb?
Thanks
Marc
 
Hallo Frank,
habe die Diskussion nur kurz überflogen. Danke aber
erstmal für den Hinweis.
Marc
 
Hi Marc,
A link that retains the message-id and goes directly to Google Groups
would be better in my opinion as it will always be idenfifiable as long as
there are newsgroups regardless of whether tinyurl continues to exist or
not, or whether Google Groups is replaced by some other archiving.
http://google.com/groups?threadm=#[email protected]

1.2.3.4.5.6 is bit much for Frank's subroutine and is converted to
1.00020003 which I think is a bit brief on what it can handle, even if it
does meet your example of what you need. I think text strings
would be better as they are not limited to 15 significant digits and
can be sorted no matter how many nodes you have.

Create a helper column for the actual sorting
=personal.xls!ChaptSort(A2)

*0001
*0001.0002
*0001.0002.0003.0004.0005.0006
*0001.0003

Function ChaptSort(cell As String) As String
Dim i As Long, j As Long, n As Long
Dim oldstr As String, newstr As String
oldstr = cell
i = 1
newstr = ""
reloop:
j = InStr(Mid(oldstr, i), ".")
If j > 5 Then
ChaptSort = "#segment"
Exit Function
ElseIf j <> 0 Then
l = j - l
newstr = newstr & "." & Left("0000", 5 - j) & Mid(oldstr, i, j - 1)
i = i + j
GoTo reloop
Else
If Len(oldstr) - i >= 4 Then
ChaptSort = "#length"
Exit Function
Else
newstr = newstr & "." & Left("0000", 3 - (Len(oldstr) - i)) & Mid(oldstr, i)
End If
End If
ChaptSort = "*" & Mid(newstr, 2)
End Function

will be included with sorttcp.htm page on my site.
If not familiar with installing and using subroutines and macros
see my getstarted.htm web page.
 
Back
Top