![]() |
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. |
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 |
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 |
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 |
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 |
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. |
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. |
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! |
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! |
All times are GMT +1. The time now is 06:03 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com