#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 37
Default Creating a button...

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 will roll.

Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 62
Default Creating a button...

On Jun 20, 12:15*pm, Markv 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 will roll.

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
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 37
Default Creating a button...

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 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 will roll.

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

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 62
Default Creating a button...

On Jun 20, 2:41*pm, Markv 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 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 will roll.


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

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 37
Default Creating a button...

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 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 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 will roll.


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




  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 62
Default Creating a button...

On Jun 20, 4:42*pm, Markv 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 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 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 will roll.


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.
  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 37
Default Creating a button...

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 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 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 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 will roll.


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.

  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 62
Default Creating a button...

On Jun 20, 5:39*pm, Markv 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 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 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 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 will roll.


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!
  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 37
Default Creating a button...

Thank you your tips is very detailed and thank you for your patience

"Nayab" wrote:

On Jun 20, 5:39 pm, Markv 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 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 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 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 will roll.


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!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
creating a button JonathanW Excel Discussion (Misc queries) 2 March 20th 07 11:12 PM
Creating a clickable button S Davis Excel Worksheet Functions 1 September 8th 06 04:53 PM
Creating a Print Button william4444 New Users to Excel 3 June 22nd 06 07:33 AM
creating a reset button 1vagrowr Excel Discussion (Misc queries) 1 December 17th 05 01:06 PM
Creating button as cell jpizzle Excel Discussion (Misc queries) 1 June 1st 05 01:22 PM


All times are GMT +1. The time now is 06:51 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"