Thread: random numbers
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Ken Wright Ken Wright is offline
external usenet poster
 
Posts: 634
Default random numbers

You can use the following, and assign it to a button on the toolbar or a
shortcut key combo. then just have the users select the range that they want to
fill, hit the button/shortcut and answer the questions as they pop up:-

Sub RandomNumber()

ubnd = InputBox("Enter Upper Bound")
lbnd = InputBox("Enter Lower Bound")
nudp = InputBox("Just hit OK for Integers or type D for decimals")
If UCase(nudp) = "D" Then
With Selection
.ClearContents
.NumberFormat = "#,##0.00"
End With
For Each cell In Selection
cell.Value = Rnd() * (ubnd - lbnd) + lbnd
Next cell
Else
With Selection
.ClearContents
.NumberFormat = "#,##0"
End With
For Each cell In Selection
cell.Value = Int(Rnd() * (ubnd - lbnd + 1) + lbnd)
Next cell
End If
End Sub

--
Regards
Ken....................... Microsoft MVP - Excel
Sys Spec - Win XP Pro / XL 00/02/03

----------------------------------------------------------------------------
It's easier to beg forgiveness than ask permission :-)
----------------------------------------------------------------------------



"travis" wrote in message
...
I am trying to devise a way to generate random numbers
within defined parameters (i.e. between 1 and 100)that
will give me a list that doesn't change everytime a
calculation is done within the workbook. The "rand"
and "randbetween" functions give me exactly what I need
for my list of numbers but there doesn't seem to be a way
to stop it from recalculating the list everytime a
calculation is done on the page. I tried the Random
Number Generation analysis tool but cant seem to find a
way to create a macro that allows for seperate parameters
when it is run. This workbook is going to be used by
children so I need it to be more user friendly than
pulling up that tool everytime the workbook is used. Any
help you can provide would be most useful. I am using
Excel 2000.



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (
http://www.grisoft.com).
Version: 6.0.562 / Virus Database: 354 - Release Date: 16/01/2004