Generate a series of non-repeating random numbers in Excel with this UDF (user defined function). This is a great function to use with statistical analysis and any other situation where you need to generate non-repeating random numbers. This is a very easy to use function and only has three arguments: one for the lowest possible random number; one for the highest possible random number; and one for the number of random numbers which you would like to display.
The one thing to note with this macro is that it will display all of the random numbers in the same cell as the function. The random numbers are separated by a space and this makes it easy to use text-manipulation functions, or the extract text UDF from this site, to pull the randomly generated numbers out of this cell.
Function RANDNUMNOREP(Bottom As Integer, Top As Integer, Amount As Integer) As String
'This UDF will generate a non-repeating set of random numbers in excel and display those in the same cell as the function
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
RANDNUMNOREP = RANDNUMNOREP & " " & iArr(i)
Next i
RANDNUMNOREP = Trim(RANDNUMNOREP)
End Function