Randomize Sheet Order

drmartell

New Member
Joined
Jun 20, 2011
Messages
4
How could I create a macro or script to randomize the order of the Sheets within my Workbook?

And why would I want to? :)

Ok I'll answer the second question - because I track an exercise program with one exercise per worksheet and I like to perform the exercises in a random order each time.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Code:
Dim oneSheet as Worksheet
Randomize

For each oneSheet in ThisWorkbook.Worksheets
    If Rnd() < . 5 Then oneSheet.Move Before:=ThisWorkbook.Sheets(1)
Next oneSheet
 
Upvote 0
Hi, Welcome.

Something like this

Code:
Sub RandSheet()
vSelected = WorksheetFunction.RandBetween(1, Sheets.Count)
Sheets(vSelected).Select
End Sub

note it is possible, and rather likely, that this will return the same sheet twice in a row.
 
Upvote 0
Thank you both,

I am now using

Code:
Sub Randomcise()
Randomize
For Each Worksheet In ThisWorkbook.Worksheets
vPosition = WorksheetFunction.RandBetween(1, Sheets.Count)
Sheets(Worksheet.Index).Move Before:=ThisWorkbook.Sheets(vPosition)
Next Worksheet
Worksheets(1).Activate
End Sub

I haven't thought it through enough to make sure it does fully randomize, but appears to be working.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,716
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top