using a macro question revisited

  • Thread starter Thread starter Adam Kroger
  • Start date Start date
A

Adam Kroger

Concerned that the thread was bypassed after going 4 deep, I have reposted
it with full includes.

The way the macro works as currently written, it can return to multiple
cells; but in this instance, I just need it to return either the sum of 2
randomly generated numbers between 1 and 6 (simulating a dice roll), or a
single randomly generated number between 1 and 6, and then have the cell be
stable after that is done (not constantly recalculating with every chnage
made to the spreadsheet).
 
Adam,

In the previous threads you were talking about UDFing the sub. As we all
explained, the sub writes to however many cells that are in the selection,
and you cannot do that in a UDF. IF you now say that you just want to add
two randomly generated numbers, then try this

Function ROll2D6()
ROll2D6 = Application.RoundUp(Rnd() * 6, 0) & _
Application.RoundUp(Rnd() * 6, 0)
End Function


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
I apologize for not being clearer from the outset., and thanks.

1 problem though, it is returning numbers outside of the 2 - 12 range.
 
I figured it out. I changed the &_ to "+" and it seems to work, at least it
isn't returning illegal values anymore.. It looks like it was multiplying
before. Am I correct?
 
& means to concatenate--usually used when you want to join strings:

msgbox "Your bill is due: " & format(date,"mm/dd/yyyy")

But you had two dice (say 5 and 4) and just jammed them together to get: 54.



"Adam Kroger
 

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

Back
Top