• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Microsoft Excel Tips and Tricks - Computergaga

  • Home
  • Excel Online Courses
  • Excel Functions List
  • Free Downloads
  • Blog
  • Tutorials
  • About
Home / Formulas / Simulate a Dice Throw in Excel

Simulate a Dice Throw in Excel

This tutorial demonstrates how to create a simulation of a dice throw in Excel.

The throw of a dice is a popular away of determining an outcome in board games. This random chance of a number between 1 and 6 provides that element of luck to games.

Download the completed dice throw simulation spreadsheet

Format the Dice to Show Spots

The first step is to format the cells so that they look like the side of a die.

  1. Select the range of cells you want to use for the dice. Cells D2:F4 have been used in this example
  2. Click the Border list arrow on the Home tab and select Outside Borders
  3. Click the Font list arrow and select Wingdings (a lowercase l in Wingdings is displayed as a spot)

Generate a Random Number Between 1 and 6

We need a function to generate a random number between 1 and 6 just like the roll of a dice. For this we need the RANDBETWEEN function.

  1. Select the cell you want to use to generate the random number simulated by the dice throw in Excel. Cell A1 is used in this example
  2. Enter the formula =RANDBETWEEN(1,6)
  3. This number can then be hidden by formatting the text to white

Display the Correct Number of Spots for the Number Generated

The next step is to make the dice display the correct number of spots to the number returned by the RANDBETWEEN function.

To do this we will use the IF function with the OR and AND functions to handle multiple criteria.

  1. Select the cells in the top left and bottom right of the dice (D2 and F4 in this example) and enter =IF(AND(A1>=2,A1<=6),”l”,””)
  2. Select the cells in the top right and bottom left (F2 and D4) and enter =IF(AND(A1>=4,A1<=6),”l”,””)
  3. Select the cells in the middle left and middle right (D3 and F3) and enter =IF(A1=6,”l”,””)
  4. Select the centre cell (E3) and enter =IF(OR(A1=1,A1=3,A1=5),”l”,””)

Click a Button to Perform Dice Throw in Excel

The RANDBETWEEN function will run every time you edit a cell or use a command in the spreadsheet. To limit it to the click of a button to roll the dice we need to turn off automatic calculation, and then insert a command button containing a macro to calculate the sheet.

  1. Click the Formulas tab on the Ribbon
  2. Click the Calculation Options button and select Manual
Set the Excel calculation options to manual
  1. Click the View tab on the Ribbon
  2. Click the list arrow on the Macros button and select Record Macro
  3. Enter a Macro name: and select This Workbook from the Store macro in: list
Record a macro to roll the dice on click
  1. Click Ok to begin the recording
  2. Click the Formulas tab and click the Calculate Sheet button
Calculate sheet button in Excel
  1. Click the Stop Recording button on the Status Bar
  2. Click the Developer tab on the Ribbon
  3. Click the Insert button, select the Button (Form Control) and draw the button onto the sheet
  4. The Assign Macro dialogue box appears. Select the required macro and click Ok
Assign a macro to a button click to roll the dice

The spreadsheet is complete. Each click of the button will initiate another dice throw in Excel.

Dice throw in Excel final product

Related Posts:

  • Sum formulas only in Excel
    Sum Formulas Only in Excel
  • SWITCH function feature
    Excel SWITCH Function - Nested IF Function Alternative
  • Live currency exchange rate in Excel thumbnail
    LIVE Currency Exchange Rate in Excel
  • N Functions in Excel thumbnail
    N Function in Excel

Reader Interactions

Comments

  1. J says

    13 January 2012 at 10:10 pm

    Check your numbers.
    The randbetween(1,6) generates an average of 3.5.
    Randbetween(0,6) generates the correct average, but doesnt simulate die throws well.
    Excel programming issue?

    Reply
    • J says

      13 January 2012 at 10:13 pm

      no wait…. nevermind….

      Reply
  2. Tracy Johnson says

    16 March 2012 at 3:38 pm

    I’m not so concerned with the graphics of rolling dice, but rather just getting a number. When rolling lots of dice for gaming I typically use the rand function and add it over and over. For an example of an 8 sided die 8 times: =TRUNC(RAND()*8+1)+TRUNC(RAND()*8+1)+TRUNC(RAND()*8+1)+TRUNC(RAND()*8+1)+TRUNC(RAND()*8+1)+TRUNC(RAND()*8+1)+TRUNC(RAND()*8+1)+TRUNC(RAND()*8+1)
    I wish there was a repeat function for numbers similar to the one for strings that could let me repeat another number function without the repeating large formula. Let’s call this new function NUMREPT:
    =NUMREPT(n,(other_function),{operator_string})
    The default operator_string would be addition “+”.
    I’d use it thus:
    =NUMREPT(8,(TRUNC(RAND()*8+1),”+”)
    Although I’d use it for rolling random numbers it should be used with other math functions.

    Reply
  3. wiki.fastserversupport.com says

    24 June 2020 at 5:38 am

    Very nice blog post. I certainly appreciate this website. Continue the good
    work!

    Reply
    • Alan Murray says

      24 June 2020 at 5:48 am

      Thank you

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Recent Posts

  • Excel SWITCH Function – Nested IF Function Alternative
  • Sum Formulas Only in Excel
  • How to Calculate Age in Excel
  • Custom Sort in Excel
  • Case Sensitive Lookup with XLOOKUP in Excel
Advanced Excel Success book

Footer

Contact

[email protected]

LinkedIn Twitter YouTube

Useful Links

  • Home
  • Excel Online Courses
  • Tutorials
  • Sitemap
  • Privacy Policy
  • Jobs by Jooble

Course Topics

  • Blog
  • Charts
  • Courses
  • Dashboards
  • Downloads
  • Excel Tips
  • Formulas
  • Mail Merge
  • Office
  • PivotTables
  • Power BI
  • Power Pivot
  • Power Query
  • VBA

Join Our Mailing List

© Copyright 2009 Computergaga · All Rights Reserved ·