random number generator

M

manclad

hi there i don't know if this is the right section, however I was
wondering is there some vba or formulae to generate random numbers in a
certain range

I would be very greatful if you can help me

Thanks

Owen
 
L

L. Howard Kittle

=rand() and pull down is the plain answer. May not meet your need's.

More info, perhaps?

HTH
Regards,
Howard
 
K

Ken Wright

Try this. Assign a keyboard combo to it, hit the combo and you will be
prompted for an upper bound, a lower bound and then as to whether you want
decimals or integers.

Sub RandomNumber()
ubnd = InputBox("Enter Upper Bound")
lbnd = InputBox("Enter Lower Bound")
nudp = InputBox("Just hit OK for Integers or type D for decimals")

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

On Error GoTo Oops:
c = Selection.Cells.Count
x = 1

If UCase(nudp) = "D" Then
With Selection
.ClearContents
.NumberFormat = "#,##0.00"
End With
For Each cell In Selection
cell.Value = Rnd() * (ubnd - lbnd) + lbnd
Application.StatusBar = Round(x / c, 2) * 100 & "% Done"
x = x + 1
Next cell
Else
With Selection
.ClearContents
.NumberFormat = "#,##0"
End With
For Each cell In Selection
cell.Value = Int(Rnd() * (ubnd - lbnd + 1) + lbnd)
Application.StatusBar = Round(x / c, 2) * 100 & "% Done"
x = x + 1
Next cell
End If

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.StatusBar = False
Oops: Exit Sub

End Sub

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

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

joeu2004

manclad said:
I was wondering is there some vba or formulae
to generate random numbers in a certain range

..... With what distribution? So far, every respondent has
ass-u-me-d you want a uniform distribution. I wonder if
you might be interested in another distribution, e.g. a
normal distribution.
 
Top