Dice Game in MS-Excel

Excel 2007 Excel 2003 Macros Excel 2007 Macros Excel 2003 Excel 2010

Games are a rage in the programming world! Everybody seems to love computer games. With the launch of the ipad, iphone and other gadgets games are becoming popular. How about creating your own game in Excel and at the same time learning how to combine old programming and domain knowledge (of the dice game!).
First we create the face of the dice that will display the points. Now we need a number to display a certain number of images on the face of the dice. We use the randbetween() function to generate the numbers between 1 and 6 - the numbers that the dice uses.

Next using the IF function we display the formatted text as 'dots'. The if function variations used to display the dots are:

(i)  =IF(OR(B6=1,B6=3,B6=5)," l "," ") - displays a single dot for one point
(ii)  =IF(AND(B6>=2,B6<=6),"l"," ") - displays the two dots in the leftmost corner at the tp and the rightmost corner at the bottom right
(iii) =IF(AND(B6>=4,B6<=6)," l "," ") - displays the two dots at the top right and the bottom left
(iv) =IF(F6=6," l "," ") - displays the two dots on the left and right middle as in the number 6

Now we connect the random generated numbers with the IF function to create the dice game.

We have also placed a command button in the Excel worksheet which on click generates the random numbers but these numbers are not visible to the players since they are white in color.

Macro code for the command button:

Private Sub CommandButton1_Click()
Range("B6") = "=randbetween(1,6)"
Range("F6") = "=randbetween(1,6)"
Range("B6").Font.ColorIndex = 2
Range("F6").Font.ColorIndex = 2

End Sub

You can watch the Excel training video below to learn how to create your own dice game in Microsoft Excel:

Excel 2007 Excel 2003 Macros Excel 2007 Macros Excel 2003 Excel 2010