Random number for dice roller

robnbomb

New Member
Joined
Dec 13, 2012
Messages
3
I have recently started using Excel and am trying to learn how to use all of the features (on my own for no better reason). I have actually started off by making little games or applications. One I wanted to work on is a Yahtzee card and dice roller. I have created the card with little problems (it auto populates scores for the most part). I tried to add a 5 dice roller on the bottom but ran into some problems. I am using the code =IF(E16=1,RANDBETWEEN(1,6),0). D16 is where I want to populate the first dice. I then created two buttons, one that puts a 1 in E16 (to generate a random 1-6 number in D16. And a button that puts a 0 in E16 to "clear" the dice. Seemed to work great. Then I added two more buttons and the code =IF(E17=2, RANDBETWEEN(1,6),0) to generate the second die. My problem is that it seems that if i hit either button to roll, it rolls both dice instead of just the one. I am trying to be able to roll 5 "dice" and keep certain ones and roll the rest (as per the rules of yahtzee). I am not entirely sure that this is possible but I thought I would ask just in case someone may know. Thanks!
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
If you're doing this in VBA, you'll want to use:
evaluate("=IF(E16=1,RANDBETWEEN(1,6),0)")

That will give you a flat number.

With any of the rand() functions... they're volatile, meaning they calculate on any workbook change.
 
Upvote 0
I tried that and it just kept that text in the box. I noticed they calculate on any change. Im guessing there is no work around?
 
Upvote 0
If you use the function, it will calculate on any change. The work around is evaluate() [the vba method, not worksheet function]<not the="" function,="" vba="" method=""> or paste special -> values.

Sidenote: I say vba method, but that might not be the correct word to describe it.. just notice i don't mean =evaluate().</not>
 
Upvote 0

Forum statistics

Threads
1,226,023
Messages
6,188,457
Members
453,475
Latest member
fmagoossens

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top