Hi there,
I had a problem back in 2014 with sorting a list of cases (http://answers.microsoft.com/en-us/office/forum/office_2007-word/sorting-a-list-of-judgments-by-case-number/17c47436-0ab8-435c-b7cd-0e6629813cad?page=1)
The issue essentially is that I have a list of around 700 cases which need to be sorted.
The list looks eg like this
Case 94/82 Kikvorsch [1983] ECR 947
Joined Cases C-153/04 and C-155/04 Nadin and Nadin-Lux [2005] ECR I-11203
Case C-108/09 Ker-Optika [2010] ECR I-122213
This list should now be sorted according to year (which is the number after the / ) and then according to case number (which is the first number).
Back in 2014 Doug had kindly helped me out with a macro which worked perfectly well. However, when I now tried to used it again it did not work.
Anyone who has an idea why this might be?
Here the macro which worked in word 2007:
Dim i As Long
Dim c1range As range, c2range As range, c3range As range
Dim atable As Table
With ActiveDocument
For i = 1 To .Paragraphs.Count
With .Paragraphs(i).range
.text = Left(.text, InStr(.text, "/") - 1) & vbTab & Mid(.text, InStr(.text, "/") + 1)
End With
Next i
.range.ConvertToTable vbTab
Set atable = .Tables(1)
End With
With atable
.Columns.Add
.Columns.Add BeforeColumn:=.Columns(2)
For i = 1 To .Rows.Count
If Left(.Cell(i, 3).range.text, 1) > 1 Then
.Cell(i, 3).range.InsertBefore "19"
Else
.Cell(i, 3).range.InsertBefore "20"
End If
.Cell(i, 5).range.text = Left(.Cell(i, 3).range.text, 4)
Set c1range = .Cell(i, 1).range
c1range.End = c1range.End - 1
If InStr(c1range.text, "-") > 0 Then
.Cell(i, 2).range.text = Format(Mid(c1range.text, InStr(c1range.text, "-") + 1), "000")
Else
.Cell(i, 2).range.text = Format(Mid(c1range.text, InStr(c1range.text, " ") + 1), "000")
End If
Next i
.Sort ExcludeHeader:=False, FieldNumber:="Column 5", _
SortFieldType:=wdSortFieldNumeric, SortOrder:=wdSortOrderAscending, _
FieldNumber2:="Column 2", SortFieldType2:=wdSortFieldAlphanumeric, _
SortOrder2:=wdSortOrderAscending
.Columns(5).Delete
.Columns(2).Delete
For i = 1 To .Rows.Count
Set c1range = .Cell(i, 1).range
c1range.End = c1range.End - 1
Set c2range = .Cell(i, 2).range
c2range.End = c2range.End - 1
Set c3range = .Cell(i, 3).range
c3range.End = c3range.End - 1
c1range.text = c1range.text & "/" & Mid(c2range.FormattedText, 3) & vbTab & c3range.text
Set c2range = c1range.Duplicate
c2range.Start = c2range.Start + InStr(c2range, "/") + 3
c2range.End = c2range.Start + InStr(c2range, "[") - 1
c2range.Font.Italic = True
Next i
.Columns(3).Delete
.Columns(2).Delete
.ConvertToText
End With
Selection.WholeStory
Selection.ParagraphFormat.TabStops.Add Position:=MillimetersToPoints(151.7), _
Alignment:=wdAlignTabRight, Leader:=wdTabLeaderDots
Thanks!