random number

M

mukhtarhope

Hi,

Can somebody tell me how to do this in Excel

I wish to create random number between 1 to 64 with reset value 0,
when a submit button is pressed a random single number is generated
between 1 to 64 and when reset button is pressed it goes back to 0 or
nil value.

Regards,
Mukhtar
 
R

Roger Govier

Hi

Add the following code to a standard module in your workbook
(instructions below if you don't know how)

Sub Generate1to64()
If Range("H1") > 0 Then
Range("H1") = 0
Exit Sub
End If
Range("H1") = "=RANDBETWEEN(1,64)"
End Sub

This uses cell H1 on the sheet, change the location to suit.
It relies upon the Analysis Toolpak, so ensure Tools>Addins>analysis
Toolpak is checked.

From the Forms toolbar, add a button to your sheet and assign the macro
above to it.

You can copy the code and paste it into your Visual Basic Editor
(VBE) in a Standard Module located in your file.
To do this,

Alt + F11 (open VBE)
Ctrl + R (open Project Explorer)
Select the file name on the left
Insert > Module
Paste code in Module

David McRitchie has lots of useful help on his site at
http://www.mvps.org/dmcritchie/excel/install.htm
http://www.mvps.org/dmcritchie/excel/getstarted.htm
 

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

Top