I've put together a random name generator (using a few other helpful threads on here) and this is the code I've come up with. It keeps outputting the list in alphabetic order, but I don't want it to. Is it being caused by aSort? I'm stumped.... Thank you!
Sub createPickList() Dim N As Long, i As Long
N = Range("E2").Value
ReDim arr(1 To N)
For i = 1 To N
arr(i) = Cells(i, "F").Value
Next i
Call aSort(arr)
For i = 1 To N
Cells(i, "G").Value = arr(i)
Next i
End Sub Public Sub aSort(ByRef InOut)
Dim i As Long, J As Long, Low As Long
Dim Hi As Long, Temp As Variant
Low = LBound(InOut)
Hi = UBound(InOut)
J = (Hi - Low + 1) \ 2
Do While J > 0
For i = Low To Hi - J
If InOut(i) > InOut(i + J) Then
Temp = InOut(i)
InOut(i) = InOut(i + J)
InOut(i + J) = Temp
End If
Next i
For i = Hi - J To Low Step -1
If InOut(i) > InOut(i + J) Then
Temp = InOut(i)
InOut(i) = InOut(i + J)
InOut(i + J) = Temp
End If
Next i
J = J \ 2
Loop
End Sub
Aucun commentaire:
Enregistrer un commentaire