# Excel Randbetween function without repeat

is there any excel function that i can use, where in a range of cells it does not give me a repeated number.

for example in a range of 200 cells, i want to put a random number from 100 to 1000000 and i do not want repeated.

is this possible?
LVL 6
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Excel VBA DeveloperCommented:
Well, you can do this with a couple of functions, but given the range of numbers you want to generate, I don't recommend this as it involves both the RANDBETWEEN function (real-time recalculation with any worksheet change) and an array function.

But for the sake of discussion:
1) in cell A1: =RANDBETWEEN(100,1000000)
2) IN CELL A2:  =LARGE(ROW(\$100:\$1000000)*NOT(COUNTIF(\$A\$1:A1,ROW(\$100:\$1000000))),RANDBETWEEN(1,(1000000+2-101)-ROW(A1))) (entered as array function with [Ctrl]+[Shift]+[Enter]).
3) Copy cell A2 and paste into A3:A200.

WARNING! This will likely take several minutes to process!  I recommend trying with on just ten-twenty rows so you can see why...it recalculates all values each iteration.

-Glenn

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Excel VBA DeveloperCommented:
What you really want is a VBA method to do this:
``````Option Explicit
Sub Unique_Random()
Dim r As Integer
Dim lngLow, lngHigh, lngRand As Long
Dim rng As Range
Dim cl As Object

lngLow = 100
lngHigh = 1000000
Range("A1").Select
For r = 1 To 200
Do
lngRand = Application.WorksheetFunction.RandBetween(lngLow, lngHigh)
Set rng = Range("A1:A" & r)
Set cl = rng.Find(lngRand)
Loop While Not cl Is Nothing
Cells(r, 1).Value = lngRand
Next r
End Sub
``````

Runs incredibly fast and inserts values instead of functions.

Regards,
-Glenn
Author Commented:
thank you Glenn
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.