Excel has no built-in “shuffle tabs” command, so the shortest working method is to right-click any sheet tab, choose View Code, paste a short macro into the Visual Basic Editor, and run it. The macro randomizes the order of every worksheet in the active workbook. If you only need to move a few tabs by hand, you can drag them instead — but for a true random shuffle across many sheets, the macro is the practical route.
What You'll Need
- Excel for Windows or Excel for Mac (the desktop app, not Excel for the web — the browser version cannot run VBA macros).
- A workbook with at least two worksheets.
- Macro security set to allow macros, or the ability to enable them for this session. In Excel for Windows this is under File > Options > Trust Center > Trust Center Settings > Macro Settings; on Mac it is under Excel > Preferences > Security. Labels can differ slightly by version, device and region.
- A backup copy of the workbook before you run any macro. Shuffling changes sheet order permanently once you save.
Step-by-Step
- Save a backup. Use File > Save As and give the file a new name (for example, “Budget – pre-shuffle”). This is your undo if the result is not what you wanted.
- Open the workbook that contains the tabs you want to shuffle. Make sure the tab you want to keep first (such as a summary or cover sheet) is not part of the shuffle — the macro below moves every worksheet.
- Open the Visual Basic Editor. Right-click any sheet tab and choose View Code. On Windows you can also press Alt + F11. On Mac, use Tools > Macro > Visual Basic Editor from the menu bar if the right-click option is not shown.
- Insert a new module. In the editor, choose Insert > Module. A blank code window appears.
- Paste this macro into the blank module:
This loop picks a random position for each sheet and moves it there, producing a shuffled order.Sub ShuffleSheets() Dim i As Long, j As Long Dim temp As Worksheet Randomize For i = 1 To ThisWorkbook.Worksheets.Count j = Int((ThisWorkbook.Worksheets.Count) * Rnd) + 1 If i <> j Then ThisWorkbook.Worksheets(j).Move Before:=ThisWorkbook.Worksheets(i) End If Next i End Sub - Run the macro. Press F5 inside the editor, or close the editor and use View > Macros (on Windows, Alt + F8), select ShuffleSheets, and click Run.
- Check the result. Look at the tab bar. If the order is not what you want, press Ctrl + Z immediately (on Mac, Command + Z). If undo does not restore the order, close the workbook without saving and reopen your backup.
- Save when happy. Use File > Save. If you want to keep the macro for later, save as an .xlsm (macro-enabled) workbook; saving as .xlsx will strip the code.
Common Mistakes
- Running the macro on the wrong workbook. The code uses ThisWorkbook, so it only shuffles the file that contains the module. If you pasted it into your Personal Macro Workbook, it will shuffle that file instead. Paste it into the workbook you want to change.
- Forgetting to save a backup. Undo does not always reverse a macro-driven sheet move. A copy is the only reliable safety net.
- Expecting Excel for the web to run it. The browser version does not support VBA. Open the file in the desktop app to run the macro.
- Saving as .xlsx after adding code. The macro is removed without warning. Use .xlsm if you want to keep it.
- Assuming hidden sheets are skipped. The macro moves every worksheet, including hidden ones. Unhide or delete sheets you do not want moved first.
Tips
- To keep a cover sheet in place, move it so it is not the first sheet, or edit the loop to start at sheet 2. A simpler approach: run the shuffle, then drag your cover sheet back to the front.
- If you shuffle often, save the macro in your Personal Macro Workbook so it is available in every file. In the editor, find VBAProject (PERSONAL.XLSB) in the Project pane and add the module there.
- Test on a copy first. A two-sheet workbook can only produce two orders, so a “shuffle” may look unchanged — that is normal, not a bug.
- If you want a repeatable order rather than a random one, sort the tabs alphabetically by right-clicking a tab and choosing Sort where available, or rename sheets with numeric prefixes and drag them into order.
Troubleshooting
- “Macros have been disabled” banner. Click Enable Content if you trust the file. If the banner does not appear, check Trust Center macro settings (Windows) or Security preferences (Mac) and allow macros for this session only.
- Nothing happens when you press F5. Make sure the cursor is inside the ShuffleSheets procedure, not in another module, and that the workbook containing the sheets is the active workbook.
- “Cannot run the macro” error. The module may be in the wrong project, or the macro name is misspelled. Reopen the editor, confirm the module sits under the correct VBAProject, and run it from View > Macros.
- The order looks the same after running. With few sheets, random chance can return the original order. Run it again, or add more sheets to see a clear change.
- You saved and lost the original order. Close without saving if you have not yet saved; otherwise restore from your backup copy or from OneDrive/SharePoint version history (File > Info > Version History).
Frequently Asked Questions
Can I shuffle tabs without a macro?
Not randomly. You can drag tabs left or right to reorder them manually, and some versions offer a Sort option on the right-click menu for alphabetical order, but Excel has no built-in random shuffle button.
Does this work in Excel for the web?
No. Excel for the web does not run VBA macros. Open the workbook in the desktop app to run the shuffle, then save and reopen it in the browser if needed.
Will shuffling break formulas or links?
No. Moving worksheets does not change cell references or formulas that point to those sheets by name. Charts and pivot tables that reference the sheets keep working.
Can I shuffle only some of the tabs?
Yes, but you need to adjust the macro. The version above moves every worksheet in the workbook, so hide or exclude the sheets you want to keep fixed before running it.
Is there an undo for a macro shuffle?
Sometimes Ctrl+Z or Command+Z reverses the last move, but not reliably across multiple sheet moves. Treat your backup copy as the real undo.
Why does the macro ask me to enable macros every time?
Excel blocks macros by default for security. You can allow them for a trusted folder in Trust Center settings, but only do this for files you created or trust.