How Do I Shuffle Or Randomize Words In Word Or Excel?

G

Guest

I have a list on microsoft word..that i want so shuffle..in no particular
order, i just want to shuffle them..but cannot figure out how to do it..i
took the microsoft certification training in high school..but apparently i
dont remember much, its a list of songs 5 words or less on each line, how do
you do this, or is it even possible, PLEASE help, or email me at
(e-mail address removed)
 
S

Shauna Kelly

Hi

Here's a macro that will shuffle the selected words. To install it, see
Graham Mayor's Idiots' Guide to Installing Macros
http://www.gmayor.com/installing_macro.htm


Sub RandomizeWordOrder()
'Shauna Kelly, 8 March 2007 for
'microsoft.public.word.docmanagement

Dim nCounter As Long
Dim vaWords As Variant
Dim lngRand As Long
Dim sOld As String
Dim sNew As String
Dim sRetval As String

On Error Resume Next

Randomize

If Selection.Characters.Last = vbCr Then
Selection.MoveEnd wdCharacter, -1
End If

vaWords = Split(Selection.Range.Text)

If UBound(vaWords) > 0 Then

For nCounter = LBound(vaWords) To UBound(vaWords)
lngRand = CLng(Int(UBound(vaWords) * Rnd + 1))
sOld = vaWords(nCounter)
sNew = vaWords(lngRand)
vaWords(nCounter) = sNew
vaWords(lngRand) = sOld
Next nCounter

For nCounter = LBound(vaWords) To UBound(vaWords)
sRetval = sRetval & vaWords(nCounter) & " "
Next nCounter

Selection.Range.Text = sRetval
Else
MsgBox "Select some text and try again"
End If


End Sub


Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 

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