Option Explicit
Private Sub Form_Load()
Dim intArray(39) As Integer, intShuffled(39) As Integer
Dim intFN As Integer
Dim strShow As String
For intFN = 0 To 39
intArray(intFN) = intFN
Next intFN
Call ShuffleArray(intArray(), intShuffled())
For intFN = 0 To 39
strShow = strShow & intFN & ") " & intShuffled(intFN) & vbTab & intArray(intFN) & vbCrLf
Next intFN
MsgBox strShow
End Sub
Private Function ShuffleArray(ByRef intArray() As Integer, ByRef intReturnArray() As Integer) As Integer
Dim intExclude() As Integer
Dim intUBound As Integer, intFN As Integer, intAssigningValue As Integer, intIndex As Integer
intUBound = UBound(intArray)
ReDim intRetVal(intUBound)
ReDim intExclude(intUBound)
For intFN = 0 To intUBound
intExclude(intFN) = -1
Next intFN
For intFN = 0 To intUBound
intAssigningValue = intArray(intFN)
intIndex = RandomInteger(0, intUBound + 1, intExclude())
intReturnArray(intIndex) = intAssigningValue
intExclude(intFN) = intIndex
Debug.Print intIndex
Next intFN
End Function
Private Function RandomInteger(ByVal intMinimum As Integer, _
ByVal intMaximum As Integer, _
intExcludeValues() As Integer) As Integer
Dim intFN As Integer, blnFound As Boolean, intExcludeValue As Integer
Randomize
blnFound = False
Do
DoEvents
RandomInteger = Int(Rnd * (intMaximum - intMinimum)) + intMinimum
For intFN = 0 To UBound(intExcludeValues())
intExcludeValue = intExcludeValues(intFN)
If RandomInteger = intExcludeValue Then
GoTo lblNotFound
End If
Next intFN
blnFound = True
lblNotFound:
Randomize
Loop Until blnFound = True
End Function