H
Harry
XL 2002
I often use this macro in several cells to generate random numbers:-
*-----------------------------------------------------------------*
Sub UniqueNums()
Function RandNums(Bottom As Integer, Top As Integer, _
Amount As Integer) As String
Dim iArr As Variant
Dim i As Integer
Dim r As Integer
Dim temp As Integer
Application.Volatile
ReDim iArr(Bottom To Top)
For i = Bottom To Top
iArr(i) = i
Next i
For i = Top To Bottom + 1 Step -1
r = Int(Rnd() * (i - Bottom + 1)) + Bottom
temp = iArr(r)
iArr(r) = iArr(i)
iArr(i) = temp
Next i
For i = Bottom To Bottom + Amount - 1
RandNums = RandNums & " " & iArr(i)
Next i
RandNums = Trim(RandNums)
End Function
*-----------------------------------------------------------*
In another macro I do a recalc. of the sheet until a certain parametre is
met.
Often, if I need to stop/interrupt this second macro (e.g. to debug) some or
all of the cells containing the RandNums function become *#Value* i.e. they
*lose* their original *=RandNums(x,y,z)* value.
Is there any way to correct this?
TIA
Harry
I often use this macro in several cells to generate random numbers:-
*-----------------------------------------------------------------*
Sub UniqueNums()
Function RandNums(Bottom As Integer, Top As Integer, _
Amount As Integer) As String
Dim iArr As Variant
Dim i As Integer
Dim r As Integer
Dim temp As Integer
Application.Volatile
ReDim iArr(Bottom To Top)
For i = Bottom To Top
iArr(i) = i
Next i
For i = Top To Bottom + 1 Step -1
r = Int(Rnd() * (i - Bottom + 1)) + Bottom
temp = iArr(r)
iArr(r) = iArr(i)
iArr(i) = temp
Next i
For i = Bottom To Bottom + Amount - 1
RandNums = RandNums & " " & iArr(i)
Next i
RandNums = Trim(RandNums)
End Function
*-----------------------------------------------------------*
In another macro I do a recalc. of the sheet until a certain parametre is
met.
Often, if I need to stop/interrupt this second macro (e.g. to debug) some or
all of the cells containing the RandNums function become *#Value* i.e. they
*lose* their original *=RandNums(x,y,z)* value.
Is there any way to correct this?
TIA
Harry