How to Shuffle PowerPoint Slides Randomly

❎ No animations! We are going to code the scoreboard counter in PowerPoint!

How to Make a Countdown Timer in PowerPoint without Animations

If you would like to shuffle your PowerPoint slides randomly so that you could present them such that the same slides do not repeat twice, you are at the right place.

Shuffle Slides Randomly In PowerPoint VBA
Total Time Needed: 5 minutes

Softwares:

- Microsoft PowerPoint
- Hyperlinks

Features:

- Sound Effects

Here is how we create an Interactive PowerPoint Quiz Game:

Step 1: Enable Developer Tab

If you're on Windows, enable the Devloper Tab by following the below mentioned steps:

Windows: Office 2010 and above: File | Options | Customise Ribbon | ☑ Developer

This will open the Visual Basic Editor to input our code. If your Microsoft Office version isn't mentioned above, click here. Note that VBA works only on Windows and MacOS.

Step 2: Open Visual Basic Editor

Windows: Developer | Visual Basic
MacOS: Office 2011 or 2016: Tools | Macro | Visual Basic Editor

This will open the Visual Basic Editor to input our code.

Step 3: Insert VBA Macro Code

The following VBA Code shuffles the set of slides from Slide 2 to Slide 7 in random order. Once the code is typed (or copy-pasted) in your VBA Module, you can adjust the FirstSlide and the LastSlide variables and run the code in the Visual Basic Editor Panel.
				
					Sub ShuffleSlides()
FirstSlide = 2
LastSlide = 7

Randomize

For i = FirstSlide To LastSlide
    RSN = Int((LastSlide - FirstSlide + 1) * Rnd + FirstSlide)
    ActivePresentation.Slides(i).MoveTo (RSN)
Next i

End Sub 
				
			

We can also run this code in Slide Show Mode in case you wish to use this interactive feature in your PowerPoint Games such as a Quiz Game where all the question slides have to be randomly shuffled. To do this, insert a shape in the first slide (or anywhere really), select the shape, go to Insert | Action | Run Macro | ShuffleSlides.

Now, if you click that shape in Slide Show Mode, your PowerPoint Slides will be randomly shuffled! 

Randomize Function in VBA

The Rnd function generates a random number from 0 to 1. For example: 0.0001 or 0.9999. It is of the data type Single, meaning that it holds decimal points. Remember to call the Randomize Function before using the Rnd Function.

Randomize randomizes the order of generating random numbers. There are many sequences or orders to generate pseudo-random numbers in VBA called seeds.

For a given seed, the same random number sequence is generated. If the first three random numbers are: 0.10, 0.90, 0.42, it will again be the same when random numbers are generated. Hence, we need to randomize the seed too by the Randomize function. It initializes the random-number generator with a seed based on the system timer.

Generating Random Number in VBA

				
					Int((upperbound - lowerbound + 1) * Rnd + lowerbound) 
				
			

The upperbound and lowerbound are the highest and lowest number in our range. Hence, in order to generate a number between 5 and 10: Int((10 – 5 + 1) * Rnd) + 5.

You can assign (store) this value to an integer variable in order to use the value. In this case, we store it in RSN and this variable represents the generated random number.

Shuffle Only Even Or Odd Slides

If you have a set of questions only on even-numbered slides or a range of odd-numbered slides which you would like to shuffle without disturbing the rest, you can use the following VBA code in PowerPoint:

				
					Sub ShuffleSlides()

EvenShuffle = True 'false if only odd-numbered slides are shuffled

FirstSlide = 2 'should be an even/odd number based on needs
LastSlide = 8

Randomize

For i = FirstSlide To LastSlide Step 2 

generate: 'generate random number between FirstSlide and LastSlide
RSN = Int((LastSlide - FirstSlide + 1) * Rnd) + FirstSlide
    If EvenShuffle = True Then
        If RSN Mod 2 = 1 Then GoTo generate
    Else
        If RSN Mod 2 = 0 Then GoTo generate
    End If

ActivePresentation.Slides(i).MoveTo (RSN)
If i < RSN Then ActivePresentation.Slides(RSN - 1).MoveTo (i)
If i > RSN Then ActivePresentation.Slides(RSN + 1).MoveTo (i)

Next i
End Sub 
				
			

Reverse PowerPoint Slides

The following VBA Macro Code will reverse the order of your PowerPoint Slides, i.e. your first slide will become the last slide, the second slide will become the second-last slide, and so on.

				
					Sub ReverseSlideOrder()
For i = 1 To 5 '2 to 5 is the slide range
ActivePresentation.Slides(5).MoveTo (i)
Next i

End Sub 
				
			

Shuffling Slides In Infinite Loop

The above tutorial shows how the PowerPoint slides can be shuffled once and played in slide-show mode in a random order such that the slides aren’t repeated. However, after one loop, the same shuffled order remains unless shuffled again.

In order to automate such that you can go through all the slides in an indefinite loop in slide-show mode, with a new randomised order for every loop, you can use the following code based on the code developed by The Tech Train

				
					Public Position, Range, AllSlides() As Integer

Sub ShuffleAndBegin()
'change values according to your presentation
FirstSlide = 2
LastSlide = 6
Range = (LastSlide - FirstSlide)

ReDim AllSlides(0 To Range)

For i = 0 To Range
AllSlides(i) = FirstSlide + i
Next i

Randomize

For N = 0 To Range
J = Int((Range + 1) * Rnd)
     temp = AllSlides(N)
     AllSlides(N) = AllSlides(J)
     AllSlides(J) = temp
Next N

Position = 0
ActivePresentation.SlideShowWindow.View.GotoSlide AllSlides(Position)

End Sub

Sub Advance()
Position = Position + 1

If Position > Range Then
ShuffleAndBegin
Else
ActivePresentation.SlideShowWindow.View.GotoSlide AllSlides(Position)
End If

End Sub
				
			

A title slide must be present with a button that runs Sub ShuffleAndBegin() and initialises the code.

Amongst all the slides in our range that would be shuffled, a shape must be placed on all those slides and the shape must run Sub Advance() on click. The first loop of randomised slides would occur on click of the shape. Once the first loop is over, the slides would be shuffled again, and on click of the shape, the next slide of the newly randomised loop will occur.

🎯 In this tutorial