I'm trying to generate n random numbers not duplicated except this numbers ( 81-82-83-84-85-86).
In this VBA code b(1 to 80) I want to do for b(1 to 200) with no repeated numbers ( 81-82-83-84-85-86) and the number_required is the number of rows in one column every time I changed it:
Dim b() As Boolean, Bidder_ID As Range, k&, x&
ReDim b(1 To 80)
Dim destination_Bidder_ID As String
Randomize
Number_required = Range("K2").Value
destination_Bidder_ID = Range("L3").Value
Range(destination_Bidder_ID).Select
For Each Bidder_ID In Range(Selection, Selection.Offset(Number_required - 1, 0))
Do
x = Int(Rnd() * 80) + 1
If b(x) = False Then
Bidder_ID.Value = x
b(x) = True
Exit Do
End If
k = k + 1: If k > 100 Then Exit Sub
Loop
Next
How can I generate random numbers from 1 to 200 except this numbers ( 81-82-83-84-85-86 ) that already exist within a defined range?
Randomizestatement right after you start the loop.