+ Reply to Thread
Results 1 to 9 of 9

Random number generating

  1. #1
    Forum Contributor dagindi's Avatar
    Join Date
    06-02-2008
    Location
    New York, NY
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    295

    Random number generating

    If i use "=RANDBETWEEN" in an equation, how can i insure that the same number never gets used twice?

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Random number generating

    You can't; you need a different approach, depending on what you're trying to do.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor dagindi's Avatar
    Join Date
    06-02-2008
    Location
    New York, NY
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    295

    Re: Random number generating

    Attached is a spreadsheet sheet which I hope will explain what I am trying to accomplish.

    Disregard Column A.

    Column B has a drop down list showing Groups 1 to 23. When a group is selected Column D populates with the Group code and the next available number (based on the formula you provided earlier.)

    I wanted to the number to be a random 5 digit number which can only be used once.

    Since that is not possible I then assigned a range of numbers to each Group consisting of 500 numbers.

    Can an equation be written that says.

    If Group 1 is selected then the first Group code is ALMC-00001
    If Group 2 is selected then the first Group code is ALPT-00500
    If Group 1 is then selected again the Group code is ALMC-00002

    so on and so forth....

    I put some notes on the attachment.

    Thanks!
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    06-11-2010
    Location
    grinnell, iowa
    MS-Off Ver
    Excel 2007
    Posts
    79

    Re: Random number generating

    I'm not sure how to code it, but as for your original question I think you might be able to do it by putting in some extra, clunky code that essentially just checks your new random number (after it has been created) against all your other previously created numbers, and deletes and tries again if there's a match. With some more time I might be able to write it, but I'm pretty slow at vba coding, so don't rely on me. If you can code yourself you might try that approach, else I'd wait for someone else to help out. In the meantime, I can try to code it a little bit today in case no else responds.

  5. #5
    Forum Contributor dagindi's Avatar
    Join Date
    06-02-2008
    Location
    New York, NY
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    295

    Re: Random number generating

    Jbm444,

    I guess you and I are the same..I can "code" once I know the basic of the code I'm trying to use...if that makes any sense... with that said i haven't even dared start with any sort of looping or self check codes.

    Hopefully one day soon....

  6. #6
    Forum Contributor
    Join Date
    12-13-2007
    Location
    Central New York
    MS-Off Ver
    Home: 2007, Office: 2010
    Posts
    158

    Re: Random number generating

    Here is a workbook I had made for random numbers, maybe it will help you, maybe not.


    Mark
    Attached Files Attached Files

  7. #7
    Forum Contributor dagindi's Avatar
    Join Date
    06-02-2008
    Location
    New York, NY
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    295

    Re: Random number generating

    Mark,

    Great spreadsheet that I am sure I will find use for. The only problem I see with what you provided is each time you press "Create", it over writes the last issued numbers. In essence I could adjust the parameters, copy and paste to the other sheet, but I am looking for a cleaner, self populating approach.

    I am going to tinker with it to see if I can get it to add more numbers without deleting the first group it generates.

    Thanks for you valuable input.

  8. #8
    Registered User
    Join Date
    06-11-2010
    Location
    grinnell, iowa
    MS-Off Ver
    Excel 2007
    Posts
    79

    Re: Random number generating

    Okay, obviously this doesn't get the checking job done, but here's the first step...

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    12-13-2007
    Location
    Central New York
    MS-Off Ver
    Home: 2007, Office: 2010
    Posts
    158

    Re: Random number generating

    dagindi,

    I figured it wouldn't be exactly what you wanted. It seems that whenever I am looking for code I always have to tweak it to fit my needs. I am glad it at leasts gives you something to work with.

    Mark

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1