Generating random numbers from a given range
I wasn't sure where you wanted the random number values to be stored. I
assumed it was in a range so I put the values in A1:A4. Did you want them in
an array?
Option Explicit
Sub ProduceRandomNumbers()
Dim MyRange As Range
Dim cell As Range
Set MyRange = Range("A1:A4")
RunAgain:
For Each cell In MyRange
cell.Value = Int((24 * Rnd) + 1)
Next cell
For Each cell In MyRange
If WorksheetFunction.CountIf(MyRange, cell.Value) 1 Then
GoTo RunAgain
End If
Next cell
End Sub
Hope this helps! If so, let me know, click "YES" below.
--
Cheers,
Ryan
"Darren" wrote:
I want to generate 4 random numbers from a range of 1 through to 24. Each
number has to be different from the other 3 though. Is there a way to do
this?
|