On Jun 20, 5:39*pm, Markv <Ma...@discussions.microsoft.com> wrote:
> thanks a million..One more question.
> Instead of displaying the result in a message box can it be shown in a cell?
>
> If so please advise...
>
>
>
> "Nayab" wrote:
> > On Jun 20, 4:42 pm, Markv <Ma...@discussions.microsoft.com> wrote:
> > > Hey there...Thanks that is spot on. cause i have created a virtual business
> > > where you control,buy and sell stock and run a business. The trick here is to
> > > see how long you can run without getting bancrupt. You can also buy personal
> > > things and so on...
>
> > > however to play this I had to replace real dies with excell type formulas
> > > and macros
> > > thanks again.
>
> > > "Nayab" wrote:
> > > > On Jun 20, 2:41 pm, Markv <Ma...@discussions.microsoft.com> wrote:
> > > > > thanks Mate, do you know the VB code for this. I have never used this type
> > > > > programming
>
> > > > > "Nayab" wrote:
> > > > > > On Jun 20, 12:15 pm, Markv <Ma...@discussions.microsoft.com> wrote:
> > > > > > > Hi all.
>
> > > > > > > Does anyone have the formula to create a button on your work sheet that upon
> > > > > > > clicking on it will give you a result?
>
> > > > > > > ie. dice rolls, I would click on the button and the dice willroll.
>
> > > > > > > Thanks.
>
> > > > > > Mark, button can be made but only button can't make things roll.. U can
> > > > > > internally rite some vb code/macro to make things happen and then u
> > > > > > need to attach the click of this button to this macro. Otherwise u can
> > > > > > insert control buttons and on click of these buttons u can write the
> > > > > > corresponding code- Hide quoted text -
>
> > > > > - Show quoted text -
>
> > > > Mark, I am not sure what exactly is ur requirement. Do you want to
> > > > display randomly picked values between 1,6 when you click a button?
>
> > > > If this is the case then, choose control toolbox and select the button
> > > > and draw it on the worksheet. Right click on this button and slect
> > > > view code.
>
> > > > On the code page, u see::::
> > > > Private Sub CommandButton1_Click()
>
> > > > End Sub
>
> > > > Change this to::::::::::::::::::
>
> > > > Private Sub CommandButton1_Click()
> > > > Dim rand_dice As Double
> > > > rand_dice = Rnd()
> > > > If rand_dice < 1 / 6 Then
> > > > rand_dice = 1
> > > > ElseIf rand_dice < 2 / 6 Then
> > > > rand_dice = 2
> > > > ElseIf rand_dice < 3 / 6 Then
> > > > rand_dice = 3
> > > > ElseIf rand_dice < 4 / 6 Then
> > > > rand_dice = 4
> > > > ElseIf rand_dice < 5 / 6 Then
> > > > rand_dice = 5
> > > > Else
> > > > rand_dice = 6
> > > > End If
>
> > > > MsgBox rand_dice
>
> > > > End Sub- Hide quoted text -
>
> > > - Show quoted text -
>
> > Mark, just to make things better, please add randomize prior to the
> > call to Rnd(). So the new code will be ------
>
> > Private Sub CommandButton1_Click()
> > Dim rand_dice As Double
> > randomize
> > rand_dice = Rnd()
> > If rand_dice < 1 / 6 Then
> > rand_dice = 1
> > ElseIf rand_dice < 2 / 6 Then
> > rand_dice = 2
> > ElseIf rand_dice < 3 / 6 Then
> > rand_dice = 3
> > ElseIf rand_dice < 4 / 6 Then
> > rand_dice = 4
> > ElseIf rand_dice < 5 / 6 Then
> > rand_dice = 5
> > Else
> > rand_dice = 6
> > End If
>
> > MsgBox rand_dice
>
> > End Sub
>
> > The randomize ensures that a new seed is taken each time.
>
> > Glad to help.- Hide quoted text -
>
> - Show quoted text -
Dude, you can do watever u like (well not all things u can think of,
but majority of them) with the number.
as u have the number in the variable rand_dice, if you want to display
it in say A1 then replace the msgbox line with:
Sheets(1).Range("A1").value = rand_dice
and u will get the value in A1 of the 1st sheet of the workbook...
Cheers!
|