Solved

Excel Randbetween function without repeat

Posted on 2014-12-03
3
2,459 Views
Last Modified: 2014-12-03
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?
0
Comment
Question by:Flora
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 500 total points
ID: 40479056
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
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40479124
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

Open in new window


Runs incredibly fast and inserts values instead of functions.

Regards,
-Glenn
0
 
LVL 6

Author Closing Comment

by:Flora
ID: 40479699
thank you Glenn
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question