
Originally Posted by
Excel Fox
Here's a way to generate unique random numbers from a minimum value to a maximum value
Assuming you meant the "from a minimum to a maximum value" to mean the user can set those values to their own values, I think your code is not correct. I believe this modification to it will perform correctly...
Code:
Sub GenerateRandomUnique() Dim lng As Long
Const lngMax As Long = 100
Const lngMin As Long = 1
With CreateObject("Scripting.Dictionary")
Do While .Count <= lngMax - lngMin 'removed the greater than symbol
lng = Rnd * (lngMax - lngMin) + lngMin 'removed the +1
.Item(lng) = Empty
Loop
MsgBox Join(.Keys, " ")
End With
End Sub
Bookmarks