How to Create a Dice Game in Excel

In this tutorial, we will be walking you through the steps of creating a simple dice game using Excel’s built-in functions and tools. This game is a great way to learn some basic Excel skills while also having fun. We will cover everything from creating a random number generator to creating a user interface for the game. By the end of this tutorial, you will have a fully functional dice game that you can customize to your liking

Creating a visual format. To create a visual format of a dice in Excel, first we need to create a background. You can add any table background or create a border if you want to. However, it is not necessary to create a border, and you can customize it in any way possible.

To create the dice box, we need to create a 3×3 grid with rows and columns. To make the row and column look more like a square, you can adjust the height and width to 52 pixels.

Creating the dots. To create the dots, set your font to Wingdings and type in the lowercase letter “L.” With this font, it will appear as a dot (●).

Creating the random number generator. A dice has six possible outcomes, and each outcome corresponds to a specific arrangement of dots on the dice. To create the game, we need a formula that can generate random numbers between 1 and 6, which will represent the outcomes of the dice roll. To do this, we will use the RANDBETWEEN function. In any cell, enter the formula: =RANDBETWEEN (1,6); in this case, the formula is in cell F4. This formula will create a random number from 1 to 6 every time you calculate.

Automating the dots. We want to make the corresponding dots appear in their correct positions, like a dice does. One dot in the middle for 1; one dot in the upper left corner and the bottom right corner for 2; and so on and so forth. To do this, we will use the IF and OR functions.

For example, in the upper left corner, we only want the dot to appear when the number in F4 is 2, 3, 4, 5, or 6. We can enter the formula: =IF(OR(F4=2,F4=3,F4=4,F4=5,F4=6),”l”,””). This instructs Excel to display the letter “l” in this cell if the number is 2, 3, 4, 5, or 6. Since the font is Wingdings, the “l” will appear as a dot.

Copy the formula to the other cells, making sure to correctly apply the conditions to each cell. To make things easier, you could use the formula above and add or remove the conditions that would make it applicable to the cell.

Since we’re creating two sets of dice, we can copy the formula from the first set to the second set of dice. We then want to total these two numbers in a single cell. To do this, we can use the SUM function. Writing the formula: =SUM(F4+J4)

Creating a button generator. Instead of using “Calculate Now” in the Formulas tab to re-generate numbers, we can create a button to make the dice regenerate numbers. To do this, we can use the ActiveX button. Here’s a step-by-step guide:

  1. In the Developer tab, click on the “Insert” button and select “ActiveX Control” from the dropdown menu.
  2. Select the “CommandButton” option from the available ActiveX controls. This will insert a button on your spreadsheet.
  3. Right click on the button click “View Code.” This will show a window showing the code for the button.
  4. In the code, write in Sheet1.Calculate and then close it.
  5. This code will re-generate numbers every time the button is pressed.
  6. To customise the button, right click on the button and then hover the ‘CommandButton Object’ and click Edit.
  7. You can then rename the button to whatever you want. In this case, we will rename it “Dice It!”

Note: Excel on MacOS doesn’t support the ActiveX feature.

Hiding the randomly generated numbers. Let’s say we want to hide the numbers that were generated by the dice game. To do this, we will have to format these cells so that they are hidden. Here’s a step-by-step guide on how to do this:

Hiding numbers in Excel is a simple process that can be done in a few steps. Here is a guide on how to hide numbers in Excel:

  1. Select the cells that contain the numbers you want to hide, in this case F4 and J4.
  2. Right-click on one of the selected cells and select “Format Cells” from the drop-down menu.
  3. In the Format Cells window, go to the “Number” tab and select “Custom” from the list of options.
  4. In the “Type” field, enter a semicolon (;)
  5. Click “OK” to close the Format Cells window.
  6. The numbers in the selected cells should now be hidden. To view the numbers again, simply repeat steps 1-3 and remove the semicolon in the “Type” field and click OK.

Conclusion

By following the tutorials provided, you should now have a better understanding of how to create a dice game in Excel, create an ActiveX button to calculate, and hide numbers in Excel. These skills can be useful in various situations, such as creating interactive spreadsheets or hiding sensitive data.