Best way is to use really large random numbers where the odds of 2 o
your 500 students getting the same random number is very small. The
Just sort the column.
I assume you want to give the students a number so you can post thei
grades. To do this, you may want to truncate the large random numbe
to 3 digits and then sort, keeping in mind that as the random numbe
gets smaller the odds of two students with the same numbe
increases....you can right a simple function to test this of course
Here is a generalized function for shuffling a 1D long array: (I then show
you how to call it with an array of numbers, 1 to 500) and place this in the
cells A1:A500
Public Function ShuffleArray(varr)
'
' Algorithm from:
' The Art of Computer Programming: _
' SemiNumerical Algorithms Vol 2, 2nd Ed.
' Donald Knuth
' p. 139
'
'
Dim List() As Long
Dim t As Long
Dim i As Long
Dim j As Long
Dim k As Long
Dim lngTemp As Long
t = UBound(varr, 1) - LBound(varr, 1) + 1
ReDim List(1 To t)
For i = 1 To t
List(i) = varr(i)
Next
j = t
Randomize
For i = 1 To t
k = Rnd() * j + 1
lngTemp = List(j)
List(j) = List(k)
List(k) = lngTemp
j = j - 1
Next
ShuffleArray = List
End Function
This shows how to call it:
Sub Main()
Dim varr()
Dim varr1
ReDim varr(1 To 500)
For i = 1 To 500
varr(i) = i
Next
varr1 = ShuffleArray(varr)
Range("A1:A500").Value = Application.Transpose(varr1)
End Sub
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.