How can I extend this code to generate a random list of numbers between 1 - 7 as many times as I define. For example if I was 3 sets of random numbers between 1 - 7 but without duplications in the first set and then in second set and then in the third set of 1 - 7s ?
eg list would read 1,2,3,4,5,6,7,1,2,3,4,5,6,7,1,2,3,4,5,6,7 but obviously the list would be random without duplication in each 1-7 set.
Also is there anyway to right this as a function?
Thanks
Public Sub GenerateRandomNumNoDuplicates()
lowerbound = 1
upperbound = 7
Set cellRange = Range("G1:G7")
cellRange.Clear
For Each Rng In cellRange
randomNumber = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Do While Application.WorksheetFunction.CountIf(cellRange, randomNumber) >= 1
randomNumber = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Loop
Rng.Value = randomNumber
Next
End Sub
Bookmarks