![]() |
Random number generation
How do I generate random numbers in a column of cells but avoid duplications.
i.e. Every cell contains a unique whole number from a specific range. |
Random number generation
have a look he
http://www.ozgrid.com/VBA/RandomNumbers.htm Neil Higgins wrote: How do I generate random numbers in a column of cells but avoid duplications. i.e. Every cell contains a unique whole number from a specific range. |
Random number generation
Hello I just made this as I was also intruiged on how to do this, not the
best way to do it no doubt but uses a bucket search and displays them in order. Sub randomCol() Dim bucket() As Boolean Dim whichCol As String Dim rndArray() As Integer Dim howManyRows As Integer Dim j As Integer Dim i As Integer rollSize = 100 'Go up to howManyRows = 10 'How many different numbers you want along with how many rows to go down ReDim bucket(1 To rollSize) For i = 1 To howManyRows If bucket(reroll(rollSize)) = False Then bucket(reroll(rollSize)) = True Else i = i - 1 End If Next i j = 1 For i = 1 To UBound(bucket) If bucket(i) = True Then Sheets("Sheet1").Cells(j, 1).Value = i j = j + 1 End If Next i End Sub Private Function reroll(rollSize) As Integer Randomize reroll = Int((Rnd * rollSize) + 1) End Function One of the problems is you can end up with a huge ass array if you wish lots of random numbers. Hope this helps! :) "Neil Higgins" wrote: How do I generate random numbers in a column of cells but avoid duplications. i.e. Every cell contains a unique whole number from a specific range. |
Random number generation
Or maybe the free Special Randoms workbook will do what you want. Download from the Products page at... http://www.realezsites.com/bus/primitivesoftware Numbers generated in a new workbook - then copy | paste where you want. -- Jim Cone Portland, Oregon USA (Excel Add-ins / Excel Programming) "Neil Higgins" <Neil wrote in message How do I generate random numbers in a column of cells but avoid duplications. i.e. Every cell contains a unique whole number from a specific range. |
Random number generation
"Neil Higgins" wrote:
How do I generate random numbers in a column of cells but avoid duplications. i.e. Every cell contains a unique whole number from a specific range. Chip Pearson has a good one he http://www.cpearson.com/Excel/randomNumbers.aspx The "no duplicates" version is about midway down the page... |
All times are GMT +1. The time now is 07:01 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com