Randomize the lines

W

Wous Mant

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
 
J

Jay Freedman

Wous said:
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
 
W

Wous Mant

Thank you Jay Freedman
Macro worked perfectly. It randomizes now how I want.
Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top