Jay
Mon Jun 14 16:22:12 CDT 2004
Wous Mant wrote:
> Hello,
> I'd like to randomize my lines in my text.
> For example my text is like this;
>
> America
> England
> Greece
> Malta
> Nigeria
> Yugoslavia
>
> I'd like it to be mixed/shuffled/randomized like this;
>
> Malta
> Yugoslavia
> England
> Nigeria
> America
> Greece
>
> Sort option only sorts in ascending or descending.Is there any way to
> do it in word ? or is there any tool which can do it?
> Thank you
Use a macro like this one. It converts the selected text (or the whole
document, if nothing is selected) to a table, adds a column, populates the
new column with random numbers, sorts the table so the numbers are in order
(which scrambles the paragraphs), and converts the table back to text.
Sub Scramble()
Dim oTbl As Table
Dim nRow As Integer, maxRow As Integer
Application.ScreenUpdating = False
If (Selection.Type <> wdSelectionNormal) _
Or (Selection.Paragraphs.Count < 2) Then
ActiveDocument.Range.Select
End If
Set oTbl = Selection.ConvertToTable(Separator:=vbCr)
With oTbl
maxRow = .Rows.Count
.Columns.Add beforecolumn:=.Columns(1)
For nRow = 1 To maxRow
.Cell(nRow, 1).Range.Text = _
CInt(Rnd() * 10 * maxRow)
Next nRow
.Sort excludeheader:=False, _
fieldnumber:=1, _
sortfieldtype:=wdSortFieldNumeric, _
sortorder:=wdSortOrderAscending
.Columns(1).Delete
.ConvertToText Separator:=vbCr
End With
Application.ScreenUpdating = True
End Sub
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ:
http://word.mvps.org