With Excel’s toolbox of thousands of formulas and VBA support, it’s not out of question to be able to create games although it’s not designed for that purpose. However, not for the sake of playing, rather for experimentation and learning, I decided to present a simple form of a spin game.
Have 2 teams/players, each picking a board for each play. Whether or not you wager some $ is up to you 🙂 Then Spin the “wheel”…doesn’t really matter which player spins it as it’s unbiased. The program will randomly fill each board with numbers from 1 through 100. You hit the jackpot for each cell that’s 99 or 100. The results are shown below each board independently for each team/player. Cells that are >=99 will show “HIT!” (otherwise, “-“) along with their relative locations in the boards. Each time, this happens a point is scored. The team with the highest number of HITS (score) wins.
The boards look like this:
The results after spin are shown as below:
Other UI Elements
There are just 2 UI elements to interact with. They’re as follows:
SPIN button will run the randomizing functions for the boards for n number of times as specified in the green cell. Default value is shown but can be changed between 5 and maximum value (set at 50 in VBA code). There’s some basic validation as we’ll see in the code later.
Here’s an animation of a game play of changing the number of times to spin (generate numbers):
Here’s an animation of the game-play:
The Logic and Formulas
For the boards, the cells contain this simple formula: =RANDBETWEEN(1,100)
Then to make it easier to read (and more visually appealing), I applied gradient color conditional formatting based on values in the board 1 (left board) such that the higher numbers (approaching max of 100) will be darker, and the lower numbers will be approaching white color.
For board 2 (right), I applied a different formatting using icons. The idea is to show 100% with 4 filled small squares inside a larger square, while lesser values will have fewer filled smaller squares using proportions. The logic is shown below:
For the results areas, I apply a gray shading for all their cells, then a formula (same for both boards’ results) which is:=IF(B4:I17>=99,”HIT!”,”-“)
This is saying that if a cell in the board above (in this case, board 1 is in B4 to I17 range) contains value >=99, in the cell containing the formula (i.e. in the results board) insert “HIT!”, otherwise put a dash. On top of that, I applied another formatting to show “HIT!” in the specified color using conditional formatting feature. This logic is copied over similarly only changing the range for the next results grid on the right.
All that is left now is to tackle the VBA code and hook it up to SPIN button.
The code is below:
It’s pretty self-explanatory, only thing to do is to assign this module to the SPIN element by right-clicking and choosing Assign Macro and choosing this module.
Hope this gives you some more ideas. Yes, you can have fun with Excel 😉