Line Randomize in MS Word

Dear Expert,

Suppose,

here 4 lines written in ms word that represent a set of question.

1. AAAAAAAAAAAAAAAAAAAAA

(a) Love (b) Hate (c) mutual (d) live

2.BBBBBBBBBBBBBBBBBBBBBBBB

(a) play (b) sky (c) milk (d)world

3.CCCCCCCCCCCCCCCCCCCCCCCC

(a) Mars (b) Apple (c) Game (d)Hot

4. EEEEEEEEEEEEEEEEEEEEEEEEEEEE

(a)Cat (b) Cow (c) Tiger (d) Home

(please tell me the short cut way or any logical treatment)

I want make more set of question within the same data/information. I mean the number of questions  will be randomized in a single click with data they held.

like:

 

2.BBBBBBBBBBBBBBBBBBBBBBBB

(a) play (b) sky (c) milk (d)world

3.CCCCCCCCCCCCCCCCCCCCCCCC

(a) Mars (b) Apple (c) Game (d)Hot

1. AAAAAAAAAAAAAAAAAAAAA

(a) Love (b) Hate (c) mutual (d) live

4. EEEEEEEEEEEEEEEEEEEEEEEEEEEE

(a)Cat (b) Cow (c) Tiger (d) Home

thanks in advance

Answer
Answer

If you select the Questions and Answers and then run a macro containing the following code, it will re-arrange them in a random order:

Dim i As Long
Dim rngqna As Range
Dim rngdup As Range
Dim rngq As Range
Dim arrqna As Variant
Dim n As Long, j As Long, k As Long
Set rngqna = Selection.Range
For i = rngqna.Paragraphs.Count - 1 To 1 Step -2
    Set rngq = rngqna.Paragraphs(i).Range
    rngq.Start = rngq.End - 1
    rngq.Text = "_"
Next i
Set rngdup = rngqna.Duplicate
rngdup.End = rngdup.End - 1
arrqna = Split(rngdup.Text, vbCr)
Randomize
For n = LBound(arrqna) To UBound(arrqna)
    j = CLng(((UBound(arrqna) - n) * Rnd) + n)
    If n <> j Then
        temp = arrqna(n)
        arrqna(n) = arrqna(j)
        arrqna(j) = temp
    End If
Next n
On Error Resume Next
For k = LBound(arrqna) To UBound(arrqna)
    rngqna.Paragraphs(k + 1).Range.Text = arrqna(k) & vbCr
Next k
rngqna.MoveEnd wdParagraph, 1
rngqna.Text = Replace(rngqna.Text, "_", vbCr)

Hope this helps,
Doug Robbins - MVP Office Apps & Services (Word)
dougrobbinsmvp@gmail.com
It's time to replace ‘Diversity, Equity & Inclusion’ with ‘Excellence, Opportunity & Civility’ - V Ramaswamy

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated March 30, 2024 Views 2,516 Applies to: