How to Create a VBA Random Selection Spinner with Countdown in Excel
Question details
The user wants to create an Excel VBA spinner that randomly cycles through a selection while displaying a countdown timer.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Creating a randomized selection tool or game within a spreadsheet that requires a visual spinning effect and a countdown indicator.
- Observed behavior
- A functioning VBA macro that repeatedly updates a counter, randomizes data using a hidden column, and maintains a responsive UI during the loop.
Ensure that your workbook is saved as a Macro-Enabled Workbook (.xlsm) and that you have enabled Developer options and macros in your Excel settings.
Creating the VBA Random Spinner with Countdown
Use a VBA loop combined with DoEvents to update the countdown timer cell and repeatedly sort a data range based on random numbers.
To achieve a spinning visual effect, the macro relies on rapidly generating new random numbers and sorting the list. The DoEvents function is critical here; without it, Excel will freeze until the countdown finishes, hiding the animation from the user.
Set up your list of items in column A. In column B, create a helper column with the formula '=RAND()' for random number generation. Designate a cell, such as D4, to display your countdown timer.
Press 'Alt + F11' to open the Visual Basic for Applications (VBA) editor. Go to 'Insert' > 'Module' in the top menu to create a new module for your macro.
Enter a VBA 'For' loop counting backward (e.g., 'For i = 100 To 0 Step -1'). Inside the loop, update your timer cell using the syntax: 'Range("D4").Value = i'.
Inside the same loop, add the code to sort the data based on your random helper column: 'Range("A1").CurrentRegion.Sort Key1:=Range("B1"), Header:=xlYes'. Immediately after the sort command, add 'DoEvents' to ensure Excel updates the screen, then end the loop with 'Next i'.
Close the VBA editor and insert a button via the Developer tab ('Insert' > 'Button'). Assign your new macro to this button and click it to watch the random spinner and countdown.

Create and Run VBA Spinners in WPS Spreadsheet
WPS Spreadsheet provides robust support for VBA macros, allowing you to build dynamic tools like random spinners and countdown timers just as you would in Microsoft Excel.
- 1. Open your macro workbook: Launch WPS Spreadsheet and open your Macro-Enabled Workbook (.xlsm) containing the spinner data.
- 2. Enable macros: Upon opening the file, click 'Enable Macros' in the security warning prompt at the top of the workspace.
- 3. Access the VBA Editor: Navigate to the 'Developer' tab and click on 'VBA Editor' or press Alt+F11 to write or modify your spinner code.
- 4. Run your spinner: Insert a form button or run the macro directly from the Developer tab to activate the randomized countdown loop.

Frequently Asked Questions
Why does my Excel freeze when running the VBA spinner loop?
If your Excel freezes, it is likely because the loop is executing too fast without allowing the screen to refresh. Ensure you include the 'DoEvents' command inside your VBA loop. This function forces the system to process screen updates and keeps the interface responsive.
How do I create the hidden random-number column for sorting?
In the column adjacent to your data list, type the formula '=RAND()'. You can then hide this column by right-clicking the column letter and selecting 'Hide'. Your VBA code can still reference and sort by this hidden column even when it is not visible.
Can I adjust the speed of the VBA countdown spinner?
Yes, you can slow down the spinner by adding a delay using the 'Application.Wait' method or the Windows API 'Sleep' function inside your loop. This pauses the code execution for a specified amount of time between spins, making the animation smoother.
Why do I get a security warning when opening my workbook?
By default, Excel and WPS Spreadsheet disable macros to protect against potentially malicious code. To run your VBA spinner, you must click 'Enable Content' or 'Enable Macros' when prompted, provided you trust the source of the spreadsheet.




