Recalculating a custom function

F

Fabian

I have made a custom dice rolling function for my spreadsheet as below.
The problem is that it does not automatically update. Normally, having
randomize(1,6) or whatever will recalulate when i press F9, but to make
this recalculate, I have to go into the cell and press enter. Is there a
way to make this recalculate normally?


Function ROLL(count As Integer, die_size As Integer) As Integer

Dim i

For i = 1 To count Step 1

Randomize
ROLL = ROLL + Int((die_size * Rnd(1)) + 1)

Next i

End Function
 
J

Jerry W. Lewis

Frank has provided the solution. As for the reason, Excel only
recalculates a function when it needs to. Application.Volatile tells
Excel that it needs to whenever anything else is calculated in the
worksheet. Otherwise it needs to only when the arguments change. Thus
the function as originally posted would only recalculate if you changed
the count or the die_size.

Jerry
 
F

Fabian

Jerry W. Lewis hu kiteb:
Frank has provided the solution. As for the reason, Excel only
recalculates a function when it needs to. Application.Volatile tells
Excel that it needs to whenever anything else is calculated in the
worksheet. Otherwise it needs to only when the arguments change. Thus
the function as originally posted would only recalculate if you
changed the count or the die_size.

Thanks, both of you. I can always rely on this group to come through
with the goods.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top