Function randomListNumberRecursive(list() As String, Optional mini As Integer, Optional maxi As Integer, Optional n As Integer) As String()
If n = maxi - mini + 1 Then
randomListNumberRecursive = list
Else
ReDim Preserve list(n)
Dim v As Integer
Dim exists As Boolean
Do
v = Int((maxi - mini + 1) * Rnd) + mini
exists = False
For i = 1 To n
If list(i) = CStr(v) Then
exists = True
Exit For
End If
Next
Loop While exists
list(n) = v
randomListNumberRecursive = randomListNumberRecursive(list, mini, maxi, n + 1)
End If
End Function
Sub test()
Dim minVal As Integer, maxVal As Integer, n As Integer, list() As String
n = 0
minVal = 6 ' Remplacez par votre valeur minimale
maxVal = 25 ' Remplacez par votre valeur maximale
Dim result() As String
result = randomListNumberRecursive(list, minVal, maxVal, n)
MsgBox Join(result, vbCrLf)
End Sub