Does anyone have a clue for a macro that can sort a list of words
according to how many letters there are in the words.
Example: I'd like the list:
bear
do
horse
a
are
to end up like:
a
do
are
bear
horse
thanks to anyone who can help!
--
per-erik
Doug Robbins - Word MVP - 19 Oct 2005 18:57 GMT
The following will do it provided that each word is in a separate paragraph:
Dim i As Long
With ActiveDocument
.Range.ConvertToTable Separator:=vbCr, AutoFit:=True
.Tables(1).Columns.Add BeforeColumn:=.Tables(1).Columns(1)
For i = 1 To .Tables(1).Rows.Count
.Tables(1).Cell(i, 1).Range = Len(.Tables(1).Cell(i, 2).Range.Text)
Next i
.Tables(1).Sort
.Tables(1).Columns(1).Delete
.Tables(1).ConvertToText
End With

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
> Does anyone have a clue for a macro that can sort a list of words
> according to how many letters there are in the words.
[quoted text clipped - 17 lines]
> --
> per-erik
Jezebel - 19 Oct 2005 22:28 GMT
Simplest is to paste the list into Excel. Use the Len() function to get the
lengths, then sort on that.
> Does anyone have a clue for a macro that can sort a list of words
> according to how many letters there are in the words.
[quoted text clipped - 17 lines]
> --
> per-erik
Doug Robbins - Word MVP - 20 Oct 2005 05:06 GMT
The following will do it provided that each word is in a separate paragraph:
Dim i As Long
With ActiveDocument
.Range.ConvertToTable Separator:=vbCr, AutoFit:=True
.Tables(1).Columns.Add BeforeColumn:=.Tables(1).Columns(1)
For i = 1 To .Tables(1).Rows.Count
.Tables(1).Cell(i, 1).Range = Len(.Tables(1).Cell(i, 2).Range.Text)
Next i
.Tables(1).Sort
.Tables(1).Columns(1).Delete
.Tables(1).ConvertToText
End With

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
> Does anyone have a clue for a macro that can sort a list of words
> according to how many letters there are in the words.
[quoted text clipped - 17 lines]
> --
> per-erik
perskram atttttt gmail dottttt com - 20 Oct 2005 10:12 GMT
> The following will do it provided that each word is in a separate paragraph:
>
[quoted text clipped - 9 lines]
> .Tables(1).ConvertToText
> End With
It worked great! Thanks!
p-e