• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 154
  • Last Modified:

Sorting tabular data by length

Hi folks

I have a mulit-column table. One of the tables contains sentences, some short and others long.

I want to sort to the data by the *length of the sentences* in a particular column.

I don't see an option when I sort so I'm assuming this calls for VBA.

Thanks.

Leprechaun
0
Leprechaun
Asked:
Leprechaun
1 Solution
 
Patrick MatthewsCommented:
SELECT Sentence
FROM Sentences
ORDER BY LEN(Sentence)
0
 
GrahamSkanCommented:
What sort of table - database, Excel, Word?
0
 
LeprechaunAuthor Commented:
Oh, I'm sorry. It's a table in MS Word.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Patrick MatthewsCommented:
Leprechaun said:
>>Oh, I'm sorry. It's a table in MS Word.

Rules out my suggestion, then :)
0
 
GrahamSkanCommented:
This will do it in VBA:

Sub SortTable()
    Dim tbl As Table
    Dim rw As Integer
    Dim s As Integer 'Sentence column
    Dim l As Integer 'last column
   
    s = 2
    Set tbl = ActiveDocument.Tables(1) 'for the frts table in the document
    tbl.Columns.Add 'temp column to hold sentence length
    l = tbl.Columns.Count
    For rw = 1 To tbl.Rows.Count
        tbl.Cell(rw, l).Range.Text = Len(tbl.Cell(rw, s).Range.Text)
    Next rw
    tbl.Sort FieldNumber:=l, SortFieldtype:=wdSortOrderDescending, Sortorder:=wdSortOrderAscending
    tbl.Columns.Last.Delete 'delete temp column
End Sub

0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now